So 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
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 ...