【发布时间】:2015-09-04 19:00:44
【问题描述】:
// 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)
}
我对上面的代码有两个问题:
- 不知道为什么会执行
Error方法,当add函数被转换成binFunc类型时? - 为什么
add函数转换后的结果能够赋值给一个err错误接口变量?
【问题讨论】:
-
请提供更详细的样本,请使用play.golang.org。我只是不明白你。什么是
add,什么是binFunc?
标签: go