type Person struct {
name string
}
type Human interface {
run()
}
type Student struct {
name string
}
func (p Person) run() {
fmt.Printf("%s is runing\n", p.name)
}
func (s Student) run() {
fmt.Printf("%s is runing\n", s.name)
}
func test() {
p := Person{name: "person"}
s := Student{name: "student"}
var human Human
human = Human(s)
human.run()
p.run()
}
func main() {
test()
}
就像如上,我都有run()方法,实现的同样的功能,这
代码会不会是多余的?