I recently learned that you can invoke a receiver's method by doing (*receiverType).method(receiver)
, where the first parameter is always the receiver itself.
func main() {
c := &Cool{}
c.say("Cool!")
(*Cool).say(c, "Hot!") // <-- this
}
type Cool struct {
}
func (it *Cool) say(s string) {
fmt.Println(s)
}
https://play.golang.org/p/vVjr42ceqA
Is there a name for this kind of syntax? Why does this compile?