Go语言中文网 为您找到相关结果 1

Golang 返回&errorString,而不是errorString的原因

Errors包 查看golang的errors包你会发现其源码是: func New(text string) error { return &errorString{text} } // errorString is a trivial implementation of error. type errorString struct { s string } func (e *errorString) Error() string { return e.s } 返回了一个实现error接口的errorString类型的指针。 那为啥不是返回errorString的值类型?? 你可能会说:因为只有 `*errorString` 才有 `Error` 方法啊... 错, 而且打错特错。 正解:...阅读全文

博文 2018-04-18 11:33:06 90design