Go 接口
当前结构体方法只要将接口上定义的方法全部实现,通过该结构体实例化后的实例就可以当为接口实例
type person interface {
walk()
talk()
smile()
}
type student struct {
name string
}
func (s student) talk() {
fmt.Println("说话", s.name)
}
func (s student) smile() {
fmt.Println("微笑", s.name)
}
func (s student) walk() {
fmt.Println("走路", s.name)
}
func main() {
var tom person = student{"tom"}
tom.talk()
}
初学linux,每学到一点东西就写一点,如有不对的地方,恳请包涵!