在Go语言中列出接口里的接口

7
我不理解container/heap包中以下代码片段的含义。
type Interface interface {
    sort.Interface   //Is this line a method?
    Push(x interface{})
    Pop() interface{}
}
1个回答

7

这是一个类型声明。

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

您可以将其视为一种继承/特化方式:这意味着实现heap.Interface接口的结构体被定义为那些实现了sort.Interface方法以及PushPop方法的结构体。

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


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接