We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
2023年10月版本,示例:
type T int func (t T) Error() string { return "bad error" } func main() { var eif interface{} = T(5) var err error = T(5) println("eif:", eif) println("err:", err) println("eif = err:", eif == err) dumpEface(eif) dumpItabOfIface(unsafe.Pointer(&err)) dumpDataOfIface(err) }
为什么在调用dumpEface(eif)后,eif的data值为bad error而不是5呢,空接口赋值为T类型值5时,也会隐式调用Error方法吗?
The text was updated successfully, but these errors were encountered:
看本仓库的chapter5/sources/dumpinterface.go。这里面dumpEface会判断i.type,如果是T类型,则调用dumpT,而后者实现如下:
func dumpT(dataOfIface unsafe.Pointer) { var p *T = (*T)(dataOfIface) fmt.Printf("\t data: %+v\n", *p) }
是这里的Printf会调用T的Error函数返回bad error。
Sorry, something went wrong.
看本仓库的chapter5/sources/dumpinterface.go。这里面dumpEface会判断i.type,如果是T类型,则调用dumpT,而后者实现如下: func dumpT(dataOfIface unsafe.Pointer) { var p *T = (*T)(dataOfIface) fmt.Printf("\t data: %+v\n", *p) } 是这里的Printf会调用T的Error函数返回bad error。
谢谢您如此及时的回复!
No branches or pull requests
Uh oh!
There was an error while loading. Please reload this page.
2023年10月版本,示例:
为什么在调用dumpEface(eif)后,eif的data值为bad error而不是5呢,空接口赋值为T类型值5时,也会隐式调用Error方法吗?
The text was updated successfully, but these errors were encountered: