Golang 中 Map[string]interface{} 必须使用 make 初始化吗?
是的,必须使用 make 函数初始化一个空的 map[string]interface{},否则会出现 'panic: assignment to entry in nil map' 错误。例如:
m := make(map[string]interface{})
m['key'] = 'value'
这样才能安全地向 map 中添加键值对。如果不使用 make 初始化 map,那么 map 将是 nil 值,无法添加键值对。
原文地址: https://www.cveoy.top/t/topic/lAmg 著作权归作者所有。请勿转载和采集!