在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
这个有点新鲜哟。。。 package main import ( "fmt" ) type notifier interface { notify() } type user struct { name string email string } func (u *user) notify() { fmt.Printf("Sending user email to %s<%s>\n", u.name, u.email) } type admin struct { user level string } func (a *admin) notify() { fmt.Printf("Sending admin email to %s<%s>\n", a.name, a.email) } //main is the entry of the program func main() { ad := admin { user: user { name: "john smith", email: "[email protected]", }, level: "super", } sendNotification(&ad) ad.user.notify() ad.notify() } func sendNotification(n notifier) { n.notify() }
|
请发表评论