package main
import "fmt"
type Duck interface {
Yaya()
}
func DuckSpeak(d Duck) {
d.Yaya()
}
type Goose struct {
}
func (g Goose) Yaya() {
fmt.Println("goose ~~~~~")
}
func (g Goose) Swin() {}
type RubberDuck struct{}
func (rd RubberDuck) Yaya() {
fmt.Println("RubberDuck ~~~~~~")
}
func main() {
fmt.Println("vim-go")
var g Goose
var rd RubberDuck
DuckSpeak(g)
DuckSpeak(rd)
}
结果
vim-go
goose ~~~~~
RubberDuck ~~~~~~
有疑问加站长微信联系(非本文作者)