// 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)
}
关于上面的代码,我有两个问题:
- 当
add
函数转换为binFunc
类型时,我不知道为什么会执行Error
方法? add
函数转换的结果是如何赋值给一个错误接口变量的?
add
,什么是binFunc
? - RoninDev