The variable a
is of type inter
, an interface, which is pointing to an impl
. The struct impl
has the inter
interface embedded in it. That means impl.aaa()
exists, which actually means impl.inter.aaa()
. However in your code impl.inter
is nil. To make it more clear:
b:=impl{}
var a inter
a=b
a.aaa() // this will call b.inter.aaa(), but b.inter is nil