// 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