Reference
Go maps in action Comparison operators
Declaration and initialization
A Go map type looks like this:
map[KeyType]ValueType
where KeyType may be any type that is comparable (more on this later), and ValueType may be any type at all, including another map!
Key types
As mentioned earlier, map keys may be of any type that is comparable. The language spec defines this precisely, but in short, comparable types are boolean, numeric, string, pointer, channel, and interface types, and structs or arrays that contain only those types. Notably absent from the list are slices, maps, and functions; these types cannot be compared using ==, and may not be used as map keys.
Code
1 | package main |
Results: 1
2
3
4
5
6panic: runtime error: hash of unhashable type map[int]int
[2020-03-30 15:06:32] INFO mp: map[{Y:[1 2 3]}:256]
goroutine 1 [running]:
main.main()
/Users/torapture/Codes/repos/go/src/go-learn/main.go:33 +0x1a2