I tried to use noinit with a []byte slice, but the parser complained that field must be a pointer to have noinit. It seems a bit unnecessary to insist on having a pointer to a slice, since a slice in itself can be nil. Consider the following code:
package main
import "fmt"
type Lala struct {
Blah []byte
}
func main() {
lala := Lala{}
if lala.Blah == nil {
fmt.Println("Blah is nil")
}
lala.Blah = []byte{}
if lala.Blah != nil {
fmt.Println("Blah is not nil")
}
}
The result is:
Blah is nil
Blah is not nil
I tried to use
noinitwith a[]byteslice, but the parser complained thatfield must be a pointer to have noinit. It seems a bit unnecessary to insist on having a pointer to a slice, since a slice in itself can benil. Consider the following code:The result is: