The code speaks for itself, I thought I was understanding reflection up until this point... It seems that the zero value of maps is nil, until you round-trip them to a reflect.Value, and they become non-nil. The code below behaves similarly for slices.
package main import ( "fmt" "reflect" ) func main() { var m map[string]interface{} if m != nil { panic("m != nil") } v := reflect.ValueOf(m) // I would expect this to panic. if !v.IsNil() { panic("v is not nil") } i := v.Interface() if i == nil { // I expect this. fmt.Println("OK") } else { // This is what happens. fmt.Printf("nil != %# v\n", i) } // output: // nil != map[string]interface {}(nil) } The above code does not panic, nor return OK. I would love to understand the mechanics of what's going on here if anyone can explain? Run in playground: https://play.golang.org/p/9XDxmotSVt -- 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+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.