【问题标题】:Listing interfaces in interfaces in Go在 Go 中的接口中列出接口
【发布时间】: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{}
}

【问题讨论】:

    标签: interface go


    【解决方案1】:

    这是一个类型声明。

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

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

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

    【讨论】:

      猜你喜欢
      • 2012-10-28
      • 1970-01-01
      • 2015-07-21
      • 2011-10-25
      • 1970-01-01
      • 2018-04-16
      • 1970-01-01
      • 1970-01-01
      • 2016-09-12
      相关资源
      最近更新 更多