接口實現
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()
}
從編輯器來看,接口有實現類