Reputation:
As far as I know methods with pointer receivers only implement interfaces for pointers. I want to utilize the encoding.TextMarshaler
interface which must be implmented with a pointer. How can I therefore obtain a pointer using reflection.
The following does not work because as mentionend a value does not implement the interface:
v.Interface().(encoding.TextUnmarshaler)
Upvotes: 1
Views: 96
Reputation: 121129
Use v.Addr().Interface().(encoding.TextUnmarshaler) to get the address. This assumes that v references an addressable value.
Upvotes: 2