3 ms·
Interesting. For pointers and interfaces, in this sample http://play.golang.org/p/Lf8nn_pcYO http://play.golang.org/p/Lf8nn_pcYO, `h3.Add2()` should fail as per
by jdkanani 11y ago
Interesting. For pointers and interfaces, in this sample http://play.golang.org/p/Lf8nn_pcYO http://play.golang.org/p/Lf8nn_pcYO, `h3.Add2()` should fail as per OP said. I am sure, I am missing something important here. Please help.
- ainar-g 11y agoIt shouldn't. The method you're calling takes a pointer receiver, and the Go Spec[1] says: >A method call x.m() is valid if the method set of (the type of) x contains m and the argument list can be assigned to the parameter list of m. If x is addressable and &x's method set contains m, x.m() is shorthand for(&x).m() In other words, if a type T no method M, it will look for M in *T's methods. [1] https://golang.org/ref/spec#Calls https://golang.org/ref/spec#Calls