// Each type have Error() string method.
// The error built-in interface type is the conventional interface for
// representing an error condition, with the nil value representing no error.
// type error interface {
// Error() string
// }
func (f binFunc) Error() string {
return "binFunc error"
}
func func_type_convert() {
var err error
err = binFunc(add)
fmt.Println(err)
fmt.Println(i)
}
我对上面的代码中的两个问题:转换功能型Golang
- 我不知道为什么
Error
方法执行,当add
功能转化为binFunc
类型? - 为什么
add
函数的转换结果能够分配给err错误接口变量?
请提供更详细的示例,请使用https://play.golang.org/。我只是不理解你。什么是'add',什么是'binFunc'? – RoninDev