我正在尝试使功能成为我的结构中的成员
type myStruct struct {
myFun func(interface{}) interface{}
}
func testFunc1(b bool) bool {
//some functionality here
//returns a boolean at the end
}
func testFunc2(s string) int {
//some functionality like measuring the string length
// returns an integer indicating the length
}
func main() {
fr := myStruct{testFunc1}
gr := myStruct{testFunc2}
}
我收到错误:
Cannot use testFunc (type func(b bool) bool) as type func(interface{}) interface{}
Inspection info: Reports composite literals with incompatible types and values.
我无法弄清楚为什么会收到此错误。
慕田峪4524236
相关分类