What does interface mean?

I understand that if T is a structure, then this means creating an empty structure (reasonable empty values) ::

 t := new(T) 

However, given the following snippet:

 type Burper interface {burp() int} b := new(Burper) 

What is being created and what is the use of the new interface?

+6
source share
1 answer

This simply creates a pointer to Burper (which is the interface). Since there is (almost) no reasonable use for a pointer to an interface, this is really Go, harmless and useless in practice.

b is a pointer and indicates a zero Burper value, which is zero.

See http://play.golang.org/p/r6h8KiA9pa

+7
source

All Articles