摘录自《Go语言实战》
package main
import "fmt"
type notifier interface {
notify()
}
//go 的struct是值类型
type user struct {
name string
email string
}
//使用值接受者
func (u user) notify(){
fmt.Printf("Sending User Email To %s<%s>
",u.name,u.email)
}
//sendNotification 接受一个实现了notifier接口的值
//并发送通知
func sendNotification(n notifier){
n.notify()
}
func main(){
//user类型的值可以调用
bill := user{"Bill","bill@email.com"}
sendNotification(bill)
}