reflect.DeepEqual() , reflect, valueInterface(), safe, Value.Interface(), safe=true. reflect.DeepEqual() () safe=false.
, Value.Interface() . , Value.String() string, Value.Float() float, Value.Int() ints .. ( ), ( "" , Value.Interface() , ).
, Value.Elem(), , / .
:
type Foo struct {
s string
i int
j interface{}
}
func main() {
x := Foo{"hello", 2, 3.0}
v := reflect.ValueOf(x)
s := v.FieldByName("s")
fmt.Printf("%T %v\n", s.String(), s.String())
i := v.FieldByName("i")
fmt.Printf("%T %v\n", i.Int(), i.Int())
j := v.FieldByName("j").Elem()
fmt.Printf("%T %v\n", j.Float(), j.Float())
}
( Go Playground):
string hello
int64 2
float64 3