October 2015
Beginner to intermediate
400 pages
14h 44m
English
reflect.ValueSo far, reflection has only interpreted values in our program in various ways. The point of this section, however, is to change them.
Recall that some Go expressions like x, x.f[1], and *p
denote variables, but others like x + 1 and f(2) do not.
A variable is an addressable storage location that contains a
value, and its value may be updated through that address.
A similar distinction applies to reflect.Values. Some are
addressable; others are not. Consider the following declarations:
x := 2 // value type variable? a := reflect.ValueOf(2) // 2 int no b := reflect.ValueOf(x) // 2 int no c := reflect.ValueOf(&x) // &x *int no d := c.Elem() // 2 int yes (x)
The value ...