Skip to content

Latest commit

 

History

History
28 lines (20 loc) · 417 Bytes

struct-pointer.md

File metadata and controls

28 lines (20 loc) · 417 Bytes

Initializing Struct References

Use &T{} instead of new(T) when initializing struct references so that it is consistent with the struct initialization.

BadGood
sval := T{Name: "foo"}

// inconsistent
sptr := new(T)
sptr.Name = "bar"
sval := T{Name: "foo"}

sptr := &T{Name: "bar"}