2

Golang 中 error(nil) 为啥 type 也是 unset?

 2 years ago
source link: https://www.v2ex.com/t/809274
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

V2EX  ›  程序员

Golang 中 error(nil) 为啥 type 也是 unset?

  BBCCBB · 11 小时 2 分钟前 · 583 次点击
m := error(nil)
n := (*error)(nil)
fmt.Printf("%T %+v \n", m, m)
fmt.Printf("%T %+v \n", n, n)

得到的结果

<nil> <nil>
*error <nil>

为啥 m 的 type 是 unset 呢?

第 1 条附言  ·  4 小时 49 分钟前

errorInterface := reflect.TypeOf((*error)(nil)).Elem()

为啥这里 TypeOf 参数用 error(nil)不行

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK