3 ms·
The nil value for a slice is an empty slice that points to constant storage: Data=0, Len=0, Cap=0. That's just not the same as Data=somethingelse, ... which you
by yencabulator 7y ago
The nil value for a slice is an empty slice that points to constant storage: Data=0, Len=0, Cap=0. That's just not the same as Data=somethingelse, ... which you get if you allocate something.
(And all Go zero values are exactly what you get with the relevant RAM filled with the zero byte.)
- lilyball 7y agoIf the nil value for a slice is the empty slice, then why do the following two variable definitions differ in behavior? var x []int; y := []int{}; Both produce a slice of capacity zero, except `x` serializes to null and `y` serializes to an empty array.