理解golang中的function types

lYng ·
package main import "fmt" type sayFunc func(name string) string type Greeting struct { f sayFunc } func (g Greeting) Say(n string) { fmt.Println(g.f(n)) } func english(name string) string { return "Hello, " + name } func french(name string) string { return "Bonjour, " + name } func main() { g := Greeting{} g.f = english g.Say("hello") g.f = french g.Say("hello") }
#1