func F(f func()interface{})interface{} {
return f()
}
func one() int {
return 1
}
type A struct {}
func two() A {
return A{}
}
func main() {
a := F(one)
b := F(two)
}
上面的代码将失败并出现错误
cannot use one (type func() int) as type func() interface {} in argument to F
cannot use two (type func() A) as type func() interface {} in argument to F
我的问题是如何将具有任何可能输出的函数作为参数传递?
慕桂英3389331
相关分类