I understand that if T
is a struct, then this amounts to creating an empty struct (sensible empty values)::
t := new(T)
However, given the following snippet::
type Burper interface {burp() int}
b := new(Burper)
What is created & what is the usefulness of new'ing an interface ?
This just creates a pointer to a Burper (which is an interface). As there is (almost) no sensible use for a pointer to an interface this is valid Go, harmless and useless in practice.
b
is a pointer and points to the zero value of Burper which is nil.