8 Aug 2012 19:23
create a value from reflect.Type
The problems is like this: type P implements interface F with pointer receiver, i.e.:
type P struct {}
type I interface {f()}
func (p *P) f() {}
I want to store the type of P, and later use this type to create a variable that implements I
So I do something like this:
pType := reflect.TypeOf(P{})
i := reflect.Zero(pType)
p := i.Interface() // p has dynamic type P, not *P, so it does not implement interface I
Given all this, how can I get a variable that implements interface I?
RSS Feed