在Go中的接口中列出接口

Her*_*rks 7 interface go

我不明白container/heap包中的以下代码片段.

type Interface interface {
    sort.Interface   //Is this line a method?
    Push(x interface{})
    Pop() interface{}
}
Run Code Online (Sandbox Code Playgroud)

Den*_*ret 7

这是一种类型声明.

heap.Interface接口嵌入sort.Interface接口.

您可以将其视为一种继承/特化:它意味着实现heap.Interface接口的结构被定义为实现sort.Interface方法PushPop方法的结构.

接口嵌入在Effective Go中有描述:http://golang.org/doc/effective_go.html#embedding