GO语言学习:map官方解释

This variable m is a map of string keys to int values:

var m map[string]int
Map types are reference types, like pointers or slices,

and so the value of m above is nil; it doesn't point to an initialized map.

A nil map behaves like an empty map when reading,

but attempts to write to a nil map will cause a runtime panic;

don't do that. To initialize a map, use the built in make function:

m = make(map[string]int)

猜你喜欢

转载自www.cnblogs.com/1521299249study/p/10070715.html