I started kidding around with Go and am a little irritated by the new
function. It seems to be quite limited, especially when considering structures with anonymous fields or inline initialisations. So I read through the spec and stumbled over the following paragraph:
Calling the built-in function new or taking the address of a composite literal allocates storage for a variable at run time.
So I have the suspicion that new(T)
and &T{}
will behave in the exact same way, is that correct? And if that is correct, in what situation should new
be used?