在Go语言中,顶级接口是指没有嵌入其他接口的接口。

huangapple go评论70阅读模式
英文:

What is the top level interface in go?

问题

所有类型都实现的接口是什么?
我正在寻找类似于Java中的Object类的东西。

我是否可以创建自己的“Root”接口?

英文:

Or what is the interface that all types implement?
I'm looking for something like the Object class in Java.

Is it possible for me to make my own kind of "Root" interface?

答案1

得分: 3

任何实现接口中列出的所有方法的类型都实现了该接口。

空接口interface{}不列出任何方法。因此,所有类型都实现它。

然而,它并没有什么“顶级”的含义。接口(尽管可以嵌入)没有层次结构。空接口只是一个没有要求的普通接口。

英文:

Any type that implements all the methods listed in the interface implements the interface.

The empty interface, interface{}, lists no methods. Therefore, all types implement it.

There is nothing "top level" about it however. Interfaces (although they can embed) do not have a hierarchical structure. The empty interface is simply a normal interface with no requirements.

huangapple
  • 本文由 发表于 2015年6月22日 08:05:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/30970542.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定