First of all let's not  confuse Go's Interfaces with Java's class
inheritance.

Read again the definition from the link you sent:

"An interface type specifies a method set called its interface. A variable
of interface type can store a value of any type with a method set that is
any superset of the interface. Such a type is said to implement the
interface."

An interface type *specifies a method set* called its interface.

So, an interface just specifies a set of methods that define that interface.

A *variable *of interface type* can store* a value of any type with a*
method set that is any superset* of the interface.

A variable of a interface type (A) that contains at least all the methods
in a another interface (B)  can store a value of that interface.

Such a type i*s said to implement *the interface

So "implementing" an interface in Go actually means that you abide by a
"contract" defined by the methods defined in that interface.

Think of set theory,  where the word "implements" could be replace by
"contains or is equal to" (⊇) and "interface" would be a "set". Then think
of "methods" as "elements".

So saying that an interface A implements interface B, is similar to saying
that set A contains or is equal to B, as it contains at least the same
elements in B.



On Wed, Jan 23, 2019 at 2:27 PM 伊藤和也 <kazya.ito.dr...@gmail.com> wrote:

> I found the explanation "All types implement the empty interface".
> https://golang.org/ref/spec#Interface_types
> So an empty interface also implements an empty interface? and again the
> empty interface implements an empty interface and the empty inter.......
> What I imagine is like this below.
>                   :
>                   :
>                   :
>        empty interface
>                   |
>        empty interface
>                   |
>        empty interface
>          |        |          |
>        int  float64  bool
>
> In java, Object class is the top.
>
>             Object
>                  |
>             Creture
>              |        |
>       Animal   Human
>        |       |
>     Dog  Cat
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to