duanba2001 2012-10-28 10:59
浏览 36
已采纳

在Go中的接口中列出接口

I don't understand the following code snippet in the container/heap package.

type Interface interface {
    sort.Interface   //Is this line a method?
    Push(x interface{})
    Pop() interface{}
}
  • 写回答

1条回答 默认 最新

  • donglu9445 2012-10-28 11:01
    关注

    This is a type declaration.

    The heap.Interface interface embeds the sort.Interface interface.

    You can see it as a kind of inheritance/specialization : it means that the structs implementing the heap.Interface interface are defined as the ones that implement the sort.Interface methods and the Push and Pop methods.

    Interface embeding is described in Effective Go : http://golang.org/doc/effective_go.html#embedding

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了