This makes people think all methods of *T are also methods of T, so the method set of T is a superset of the method set of *T.
In fact, it is just the contrary.
--
You received this message because you are subscribed to the Google Groups "golang-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Are you asking where in the Go spec allows that, or what the rationale for allowing it is?For the former, see this sentence from https://golang.org/ref/spec#Calls:"If x is addressable and &x's method set contains m, x.m() is shorthand for (&x).m()"For rationale, it's because writing (&x).m() everywhere would be inconvenient. Just like how Go allows p.f as shorthand for (*p).f for accessing struct fields.
I just feel the benefit of shortening (&x).m() to x.m() is smaller than the confusion it brings.
On Wednesday, July 13, 2016 at 11:35:52 PM UTC+8, Matthew Dempsky wrote:Are you asking where in the Go spec allows that, or what the rationale for allowing it is?For the former, see this sentence from https://golang.org/ref/spec#Calls:"If x is addressable and &x's method set contains m, x.m() is shorthand for (&x).m()"For rationale, it's because writing (&x).m() everywhere would be inconvenient. Just like how Go allows p.f as shorthand for (*p).f for accessing struct fields.
I just feel the benefit of shortening (&x).m() to x.m() is smaller than the confusion it brings.