Golang:此类型实现哪种接口?

In essence, four questions are here for Golang interfaces, with each one slightly harder than the one before it.

  1. say we imported a lot of interfaces, A, B, C, ..., G
import (
    "A",
    "B",
    "C",
    // more ...
    "G"
)

and we define a type S:

type S struct {
    // more ...
}

now if S "implements" one of the interfaces:

func (s S) Foo() {
    // more ...
}

Up to date, is there any other way to tell which interface of A - G does S implement, except for looking and searching into interface declarations of A - G? If no, is there a way to explicitly tell S to implement which interface? So far, it appears that the which interface S implemented is inferred.

  1. If, for the same example, B, C, D interfaces all have the Foo() method with the same signature. In this case, which interface does S implement? Does it depend on the order those interfaces are imported from B, C, and D?

  2. If, rather than importing interfaces, we declare and define interfaces B, C, D in the same file, but those interfaces again all have Foo() method with the same signature, which interface does S implement? Does it depend on the order those interfaces are declared, or defined?

  3. If, we declared and defined B, C, D interfaces in the same file, B has Foo() method, C has Bar() method, and D has both Foo() and Bar(). Now if S implement Foo() and Bar(), then does S implement B and C, or S only implements D?

Thanks, everyone!

  1. No. (But as a side note, you don't import interfaces, you import packages.)

  2. All of them. Order doesn't matter. If you declared variables of type B, C, and D, all of them would be able to hold an S.

  3. All of them. What you do in the same or different files doesn't matter.

  4. All of them. S implements B because S has Foo(). S implements C because S has Bar(). S implements D because S has both Foo() and Bar().