Can someone explain what is the subtle difference between these two notations: (*T)(nil)/new(T)and &T{}.
type Struct struct {
Field int
}
func main() {
test1 := &Struct{}
test2 := new(Struct)
test3 := (*Struct)(nil)
fmt.Printf("%#v, %#v, %#v \n", test1, test2, test3)
}
It seems that the only difference between this (*T)(nil)and the other is that it returns a nil pointer or not a pointer, but still allocates memory for all Struct fields.
source
share