Perhaps for clarity, the trip through reflect is a red herring. All you
need is to put the map in an interface:
package main
>
> import (
> "fmt"
> )
>
> func main() {
> var m map[string]interface{}
> if m != nil {
> panic("m != nil")
> }
> var i interface{} = m
> 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 reason the interface is non-nil in this case is described in Ian's link.
On Mon, Aug 8, 2016 at 1:27 PM Ian Lance Taylor <[email protected]> wrote:
> On Mon, Aug 8, 2016 at 10:07 AM, Sam Salisbury <[email protected]>
> wrote:
> > 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.
>
> This is an instance of https://golang.org/doc/faq#nil_error .
>
> Ian
>
> --
> 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 [email protected].
> For more options, visit https://groups.google.com/d/optout.
>
--
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 [email protected].
For more options, visit https://groups.google.com/d/optout.