3 ms·
In Go, it's called "zero value", not "nil value". It's also not an implicit conversion from nil to something. Nil isn't a value the way 0 is a value of an inte
by kjksf 10y ago
In Go, it's called "zero value", not "nil value".
It's also not an implicit conversion from nil to something. Nil isn't a value the way 0 is a value of an integer or "foo" is a value of string.
Per Go spec (https://golang.org/ref/spec https://golang.org/ref/spec) nil is "predeclared identifier which has no type". That implies it doesn't have a value and therefore cannot be converted to a value.
Nil is zero value of pointer types (which in practice end up being a pointer whose value interpreted as integer is 0) and also a zero value of interface type (which is interface without a type and without a value) and a few other types.