comparison between map initialization
tags: learning go programming diff-between
content
var m map[int]int
- returns
map[int]int - value of
misnil(nil map) - readable, not writable,
m[1] = 1gives errorm =: new(map[int]int) - returns
*map[int]int, it’s a pointer - value of
mis the address of a nil map - readable, not writeable
m =: make(map[int]int) - returns
map[int]int, not a pointer - value of
mis an empty map, NOT a nil map - readable, writable.
m[1] = 1works