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)

posted on 2018-12-05 14:24  码农er  阅读(118)  评论(0编辑  收藏  举报