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.
### version
1. Go: 1.14.2
2. The Go Programming Language Specification: Version of Jan 14, 2020
### code
```
type T struct {
ID int64
Name string
}
func (p T) GetNameA() string {
return p.Name
}
func (p *T) GetNameB() string {
return p.Name
}
func TestUser(t *testing.T) {
obj := T{ID: 1, Name: "T"}
na := obj.GetNameA()
nb := obj.GetNameB()
log.Printf("na=%v nb=%v", na, nb)
}
```
### output log
```
=== RUN TestT
2020/09/04 17:12:52 na=T nb=T
--- PASS: TestT (0.00s)
PASS
```
Thanks
YUU
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/golang-nuts/2A9FA227-E88B-4E2F-9244-59E2B5204FEE%40gmail.com.