Null value in Go
Solution 1:
The equivalent of NULL
is nil
, as you already discovered. Note, though, that you don't generally need to initialize things to nil
or zero in Go, because by default all variables (including dynamically allocated ones) are set to “zero values” according to type (numbers zero, references nil
). So in your example saying new(Node)
would result in a Node with both fields nil
.
Solution 2:
I just found out is nil
Solution 3:
nil
is the NULL in golang. .
Solution 4:
I think Understanding Nil is an excellent and comprehensive intro of nil
in Go
. You can also watch the presentation video here.