* Yuu LongXue <
longx...@gmail.com> [200904 05:31]:
> Hi all,
>
> I’m confused by the "method set" defined in go
> specification,any one can help explain?
>
> The Go Programming Language Specification says that :
> ```
> The method set of any other type T consists of all methods
> declared with receiver type T. The method set of the
> corresponding pointer type *T is the set of all methods declared
> with receiver *T or T (that is, it also contains the method set
> of T).
> ```
> but actually, the type T can use the method with receiver *T ,
> which is described as bellow.
In addition to Brian's answer, the method set definition is specifically
about which types satisfy a particular interface. While the part of the
spec that Brian quoted describes a convenience shorthand, it does not
mean that a method declared with receiver *T is in the method set of
type T. This is a subtle point that can be confusing.
The playground link
https://play.golang.org/p/N5IvMNvEsxi illustrates
this point. Note that you can call car.String() (line 38), but you
cannot assign car to a variable of type Stringer (line 43 produces a
compiler error). If you insert an '&' in front of car on line 43, it
compiles and runs.
This point is worth understanding.
...Marvin