如何在 Go 中表示“ null”值?

如何在 Go 中表示“ null”值?

type Node struct {
next *Node
data interface{}
}

我想说

return &Node{ data: NULL, next: NULL }
126244 次浏览

I just found out is nil

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.