You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, methods are not allowed to have an interface receiver or an interface pointer receiver. While methods with interface (value) receivers are clearly not possible, methods with interface pointer receivers (and consequently having interface pointers implement other interfaces) should be possible. This would be extremly useful for cases such as unmarshaling polymorphic JSON.
typeMyInterfaceWrapperstruct {
wrappingMyInterface
}
func (p*MyInterfaceWrapper) UnmarshalJSON(data []byte) error { ... }
varobjMyInterfaceWrapperjson.Unmarshal(&obj)
// pull out value from wrapping field
Just to clarify what you are proposing, is there anything this proposal permits that we couldn't do with an approach like that?
Thanks, but since this proposal would make the relationship between interfaces and methods more confusing, and since it would not add functionality that we can't already get in other ways, we aren't going to move this forward with this proposal.
What version of Go are you using (
go version
)?Currently, methods are not allowed to have an interface receiver or an interface pointer receiver. While methods with interface (value) receivers are clearly not possible, methods with interface pointer receivers (and consequently having interface pointers implement other interfaces) should be possible. This would be extremly useful for cases such as unmarshaling polymorphic JSON.
For example:
The text was updated successfully, but these errors were encountered: