【发布时间】:2018-04-03 23:13:08
【问题描述】:
我有以下定义:
func (c *Collector) RegisterSource(f func() []interface{}) {
c.source = f
}
我尝试如下调用它,但得到一个错误:
func source() []int {
return []int{ 0, 1, 2, 3, 4 }
}
...
c.RegisterSource(source)
遇到这样的情况:
cannot use source (type func() []int) as type func() []interface {} in argument to c.RegisterSource
【问题讨论】:
-
这可能是重复的,但无论如何这应该会有所帮助:github.com/golang/go/wiki/InterfaceSlice
-
很明显,它们是不同的类型。
-
来自 Go 常见问题解答:golang.org/doc/faq#convert_slice_of_interface