Is there any way to check whether the value stored in a non-nil interface is nil when you don't know the type, short of using reflect.Value.IsNil()?
Thanks. On Wednesday, February 15, 2017 at 10:11:55 AM UTC-8, rog wrote: > > In addition to what others have said, note that the > comparison works as you expected if you use a typed nil: > > https://play.golang.org/p/jA57mTKbxa > > > On 15 February 2017 at 08:40, Felix Sun <[email protected] <javascript:>> > wrote: > > https://play.golang.org/p/qYA8Ddnnye > > > > ``` > > > > package main > > > > import ( > > "fmt" > > ) > > > > type Obj struct { > > One *Obj > > } > > > > func main() { > > var o = &Obj{} > > > > var arr = []interface{}{o.One} > > > > fmt.Println(arr[0]) > > fmt.Println("why this is not true?", arr[0] == nil) > > } > > > > > > ``` > > > > > > Why `arr[0] == nil` is not true? > > > > -- > > 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] <javascript:>. > > 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.
