【发布时间】:2016-12-11 19:01:04
【问题描述】:
在 golang 中,如果您创建一个结构体,其中包含未初始化的映射,则打印映射会产生非 <nil> 字符串。
为什么 nil 映射的 "print" 输出 "map[]" 而不是 <nil> ?
// Assume above there is a struct, a.AA, which is created but which otherwise
// has not created the map.
//output:
//map[]
//map[]
fmt.Println(a.AA)
fmt.Println(make(map[string]int64))
【问题讨论】:
-
格式化程序就是这样打印的。这只是为了方便,所以显示类型很有用(更不用说你可以从 nil 映射索引)
-
@JimB 这就是答案,贴出来。
标签: dictionary go null