package main
import "fmt"
type I interface {
getIndex() int
}
type B struct {
index int
}
func (self *B) getIndex() int {
return self.index
}
func test(is []I) {
for _, i := range is {
fmt.Println(i.getIndex())
}
}
func main() {
bs := []*B{
&B{index:1},
&B{index:2},
}
test(bs)
}
cannot use bs (type []*B) as type []I in argument to test
为什么[]*B不能转换成[]I 都实现了 getIndex方法
I(&B{index:1}) 是没问题的
go的继承,多态怎么不符合逻辑