For a map that has a nil key (and a value associated with it, of course):
mapp := map[interface{}]interface{}{
nil: "a",
}
Accessing it’s nil key directly works:
fmt.Println("key[nil]:", mapp[nil])
But using reflection it doesn’t - how to do this?
rmapp := reflect.ValueOf(mapp)
rkey := reflect.ValueOf(interface{}(nil))
rval := rmapp.MapIndex(rmapp.MapIndex(rkey)) // panic: runtime error: invalid memory address or nil pointer dereference
fmt.Println("key[nil]:", rval)
Non-working code here:
https://play.golang.org/p/sCPpmpOUJw
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.