4 ms·
Multiple nil types in Go.
- _ak 13y agoBut: http://play.golang.org/p/J46-8OEWYS http://play.golang.org/p/J46-8OEWYS
- eonil 13y agoThis is even more interesting.
- cgearhart 13y ago`make` allocates and initializes `a`, setting it to nil effectively uninitializes the variable. See below, where I declare `c`, but don't initialize it. From the Golang spec, http://golang.org/ref/spec#Map_types http://golang.org/ref/spec#Map_types, the value of an uninitialized map is nil. http://play.golang.org/p/J46-8OEWYS http://play.golang.org/p/J46-8OEWYS
- _ak 13y agoDon't tell me, I merely added one line of code to show that more information than the interface{} being nil is kept.
- deleted 13y ago[deleted]
- Xlab 13y agoOh I think I found what happens, see http://golang.org/doc/faq#nil_error http://golang.org/doc/faq#nil_error
- LocalMan 13y agoIn 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 13y agoIt'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.