Go Interfaces: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 11: Line 11:
=Declaration=
=Declaration=


The interface declaration is introduced by the <tt>type</tt> keyword, to indicated that this is a user-defined type, followed by the interface name and the keyword <tt>interface</tt>. Unlike in the <tt>struct</tt>'s case, we don't define fields but a ''method set''.
The interface declaration is introduced by the <tt>type</tt> keyword, to indicated that this is a user-defined type, followed by the interface name and the keyword <tt>interface</tt>. Unlike in the <tt>struct</tt>'s case, we don't define fields but a ''method set''. The method set is a list of methods


<pre>
<pre>

Revision as of 17:07, 30 March 2016

Internal

Overview

Interfaces are not types.

Can only structs be interfaces, or there are other things that can be interfaces?

Declaration

The interface declaration is introduced by the type keyword, to indicated that this is a user-defined type, followed by the interface name and the keyword interface. Unlike in the struct's case, we don't define fields but a method set. The method set is a list of methods

type MyInterface interface {
     functionName1() return_type
     functionName2() return_type
     ...
}

Initialization