【发布时间】:2019-04-03 11:48:28
【问题描述】:
代码:
package main
import "fmt"
type implementation struct {
d []int
}
func (impl *implementation) getData() interface{} {
return impl.d
}
type phase struct{}
type data interface {
getData() interface{}
}
func MakeIntDataPhase() *phase {
return &phase{}
}
func (p *phase) run(population []data) []data {
return nil
}
func main() {
var population []implementation
MyPhase := MakeIntDataPhase()
fmt.Println(MyPhase.run(population))
}
在操场上运行以下代码时出现以下错误:prog.go:30:25: cannot use population (type []implementation) as type []data in argument to MyPhase.run
我是 golang 新手,不明白为什么会这样?
struct implementation 从data 接口实现方法getData()。在run 方法中使用implementation 的一部分还不够吗?
我的推理哪里错了?
【问题讨论】:
标签: go