【发布时间】:2012-10-17 23:26:57
【问题描述】:
我看不懂container/heap包里下面的代码sn-p。
type Interface interface {
sort.Interface //Is this line a method?
Push(x interface{})
Pop() interface{}
}
【问题讨论】:
我看不懂container/heap包里下面的代码sn-p。
type Interface interface {
sort.Interface //Is this line a method?
Push(x interface{})
Pop() interface{}
}
【问题讨论】:
这是一个类型声明。
heap.Interface 接口嵌入了sort.Interface 接口。
您可以将其视为一种继承/特化:这意味着实现heap.Interface接口的结构被定义为实现sort.Interface方法和Push和Pop方法的结构。
Effective Go 中描述了接口嵌入:http://golang.org/doc/effective_go.html#embedding
【讨论】: