Selectors
…
- For a value
x
of typeI
whereI
is an interface type,x.f
denotes the actual method with namef
of the dynamic value ofx
. If there is no method with namef
in the method set ofI
, the selector expression is illegal.
type I interface {
Greet()
}
type Person struct {
Name string
}
func (p *Person) Greet() {
fmt.Printf("Hello, %s", p.Name)
}
var I x
x = &Person{}
x.Greet // denotes the actual Greet method Person, which is the dynamic value of x
Quotes from The Go Programming Language Specification Version of August 2, 2023