接口实现
go语言中的接口实现是一种隐式实现
import "fmt"
type Say interface {
sayhello()
saybye()
}
func (t people) sayhello() {
fmt.Println("hello")
}
// people这个struct 实现Say接口的 saybye方法
func (t people) saybye() {
fmt.Println("bye")
}
type people struct {
age int
name string
}
func main() {
// people赋值给say
var say Say = people{21, "aa"}
say.sayhello()
say.saybye()
}
从编辑器来看,接口有实现类