Here is the code, I expect it will panic when visiting mp["12"], but it works fine there
// You can edit this code!
// Click here and start typing.
package main
import "log"
func main() {
var mp map[string]int = nil
log.Println(mp["12"], "12") // works fine
if mp == nil {
panic("wtf") // panic here
}
}
>Solution :
You can read from a nil map, but cannot write to it. The language spec says:
A nil map is equivalent to an empty map except that no elements may be added.