* Yuu LongXue <longxue...@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

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/20200904141109.rp6cqmlidpczj37n%40basil.wdw.

Reply via email to