You used pv.Type().Elem(). pv.Type() is the reflect type for "interface{}".
Since this is now just a type, not a value, Elem doesn't make sense.
An interface type could have nearly any type inside it. Statically,
you don't know.
If you use pv.Elem().Type() you will get the type of the thing inside the
interface, because pv is a reflect value for a specific interface{} value.
You can call Elem() to get the thing inside the interface value and
then call Type on that (unless the interface value is nil).
Russ
Interfaces don't point. They contain other values.
It sounds pedantic but it's important to remember
that an interface value is different from a pointer.
> I guess that the first 'ifoo' and second 'ifoo' both should work with same
> approach in following code.
> ifoo = pfoo
Notice that you set this and never used it.
> pv = reflect.ValueOf(&pfoo).Elem()
Here, pfoo has type *foo.
&pfoo has type **foo.
ValueOf(&pfoo) is a Value corresponding to a **foo.
ValueOf(&pfoo).Elem() is a Value corresponding to a *foo.
In fact, it corresponds exactly to pfoo.
pv.Set(ValueOf(x)) and pfoo = x will have the same effect.
> zv = reflect.New(pv.Type().Elem())
pv.Type() is the Type for *foo.
pv.Type().Elem() is the Type for foo.
New(pv.Type().Elem()) is like ValueOf(new(foo)).
> pv.Set(zv)
So this is basically the same as pfoo = new(foo).
> ifoo = vfoo["foo"]
Okay, so ifoo is an interface{} containing a *foo pointer.
> pv = reflect.ValueOf(&ifoo).Elem()
Here you used the same idiom to get something
corresponding exactly to ifoo. Now,
pv.Set(ValueOf(x)) and ifoo = x will have the same effect.
(This is different from before: note ifoo, not pfoo.)
pv is a Value corresponding to an interface{}.
> zv = reflect.New(pv.Type())
pv.Type() is the Type for interface{}.
So reflect.New(pv.Type()) is like ValueOf(new(interface{})).
> pv.Set(zv)
This is like ifoo = new(interface{}).
Russ