On Friday, 4 September 2020 10:31:11 UTC+1, Yuu LongXue wrote:
>
> 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. 
>
>
It's because of the automatic referencing and dereferencing of pointers.

"If x is addressable <https://golang.org/ref/spec#Address_operators> and &x's 
method set contains m, x.m() is shorthand for (&x).m():"
https://golang.org/ref/spec#Calls

You are also using it in the opposite direction: inside GetNameB, p.Name is 
shorthand for (*p).Name.

-- 
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/b16c5355-6ac9-494f-a968-2e11882d8012o%40googlegroups.com.

Reply via email to