package main import( "fmt" "reflect" ) func main() { var m map[string]int // https://blog.golang.org/go-maps-in-action // 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 // Map类型 是引用类型,因此 m 的值为 nil fmt.Printf("type of un-initialized map reference %vn", reflect.TypeOf(m)) fmt.Printf("type of the pointer of map reference %vn", reflect.TypeOf(&m)) fmt.Printf("The un-initialized map reference %pn", m) fmt.Printf("The pointer of map reference %pn", &m) // The make function allocates and initializes a hash map data structure // and returns a map value that points to it. The specifics of that data structure // are an implementation detail of the runtime and are not specified by the language itself. // make函数将会分配并初始化一个底层hash map结构,然后返回一个 map 值,该值指向底层的hash map结构 m = make(map[string]int) fmt.Printf("The initialized map reference %pn", m) fmt.Printf("type of initialized map reference %vn", reflect.TypeOf(m)) fmt.Printf("The pointer of map reference %pn", &m) }