top | item 7016050

Multiple nil types in Go.

7 points| eonil | 12 years ago |play.golang.org | reply

7 comments

order
[+] LocalMan|12 years ago|reply
In Go, nil is a value, not a type. Assigning 'nil' to an interface only assigns the value, not the type. An interface has both a value and a type at runtime, but is "nil" only if both the value and the type are nil.
[+] eonil|12 years ago|reply
It's really hard to think the term nil is a value.

IMO, this is a bug in language design. If it's truly a value, I think they should choose a different term rather then `nil` as like they choose `panic/recover` instead of `throw/catch` because they're semantically different.

And also, I really don't know how should I detect nil reliably for an interface type.