October 2015
Beginner to intermediate
400 pages
14h 44m
English
reflect.Type and reflect.Value
Reflection is provided by the reflect package.
It defines two important types, Type and Value.
A Type represents a Go type.
It is an interface with many methods for discriminating among types
and inspecting their components, like the fields of a struct or the
parameters of a function.
The sole implementation of reflect.Type is the type
descriptor (§7.5), the same entity that identifies the
dynamic type of an interface value.
The reflect.TypeOf function accepts any interface{}
and returns its dynamic type as a reflect.Type:
t := reflect.TypeOf(3) // a reflect.Type fmt.Println(t.String()) // "int" fmt.Println(t) // "int"
The TypeOf(3) call above assigns the value 3 to the ...