Open hhow09 opened 1 year ago
&x
generates a pointer of type *T
to x. The operand must be addressable, that is, either a variable, pointer indirection, or slice indexing operation
&m["key"] // values in a map
&afunc() // return values from function
&t.method() // method calls
v := afunc()
&v
Reflection
Overview
Laws of Reflection
1. Reflection goes from interface value to reflection object.
2. Reflection goes from reflection object to interface value.
3. To modify a reflection object, the value must be settable.
Kind
Although there are infinitely many types, there are only a finite number of kinds of type: the basic types Bool, String and all the numbers; the aggregate types
Array
andStruct
, the reference typesChan
,Func
,Ptr
,Slice
andMap
;interface
types; and finally Invalid, meaning no value at all (The zero value of a reflect.Value has kind Invalid).Reference