在一个包中,我有这个:
package pkg1
type SomeFuncType func (a interface{}, b interface{}) int
func PkgApiCall (x SomeFuncType) {
...
}
在使用此程序包的代码中,我有一些非常相似的内容:
type MyFuncType func (a interface{}, b interface{}) int
现在,我要调用pkg1.PkgApiCall()
,但使用MyFuncType
as参数的变量:
package mypackage
func doingSomeThing(x MyFuncType) {
pkg1.PkgApiCall(x)
}
它不会编译。我得到了错误
./src1.go:97:7: error: incompatible type in initialization (cannot use type mypackage.MyFuncType as type pkg1.SomeFuncType)
我该如何克服?这些函数类型定义具有完全相同签名的函数。
通常的类型转换适用于函数类型,也适用于非函数类型:
pkg1.PkgApiCall(SomeFuncType(x))
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句