简单接口
type Painter interface {
Paint()
}type Rembrandt struct{}
func (r Rembrandt) Paint() {
// use a lot of canvas here
}var p Painter
p = Rembrandt{}type Singer interface {
Sing()
}
type Writer interface {
Write()
}
type Human struct{}
func (h *Human) Sing() {
fmt.Println("singing")
}
func (h *Human) Write() {
fmt.Println("writing")
}
type OnlySinger struct{}
func (o *OnlySinger) Sing() {
fmt.Println("singing")
}空接口
接口值
最后更新于