本文共 590 字,大约阅读时间需要 1 分钟。
这个有点新鲜哟。。。
package mainimport ( "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 programfunc main() { ad := admin { user: user { name: "john smith", email: "john@yahoo.com", }, level: "super", } sendNotification(&ad) ad.user.notify() ad.notify() }func sendNotification(n notifier) { n.notify()}
转载地址:http://zuesa.baihongyu.com/