在初始化结构引用时,请使用&T{}代替new(T),以使其与结构体初始化一致。
&T{}
new(T)
//bad usage sval := T{Name: "foo"} // inconsistent sptr := new(T) sptr.Name = "bar" //good usage sval := T{Name: "foo"} sptr := &T{Name: "bar"}
Last updated 4 years ago
Was this helpful?