接口成员是抽象的吗?
嗯,我知道接口中的成员表现得好像它们是抽象的,但它们实际上是抽象的吗?我的意思是我不需要使用该关键字,所以我不确定它是否是隐式的,或者它们在技术上并不抽象......希望它有意义
Well I know members in an interface act like they were abstract, but are they abstract actually? I mean that I do not need to use that keyword so I am not sure whether its implicit or they are not abstract technically...Hope it makes sense
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
它们不是抽象的——它们是由接口定义的契约。 “抽象”具有仅适用于类的特定含义。
也就是说,它们的行为与类中的抽象成员非常相似 - 任何实现接口的类型都必须实现该成员或者本身是抽象的。
They are not abstract - they are a contract defined by the interface. "abstract" has a specific meaning which only applies to classes.
That being said, they act very similarly to an abstract member in a class - any type implementing the interface must either implement the member or be abstract itself.
它们在概念上是抽象的,因为实现接口的类必须实现每个成员或将自身声明为抽象。
从技术意义上来说,它们不是抽象的,因为只有类才是抽象的。
They are abstract in concept, as a class that implements the interface must either implement every member or declare itself to be
abstract
.They are not
abstract
in a technical sense, as only classes areabstract
.没有。抽象方法隐式地是虚拟的。
接口实现不需要是虚拟的。 (事实上,可以显式地实现“冲突”接口(即声明相同成员签名的接口)。这对于
vtable singledispatch
[1]是不可能的,因为单个vtable槽不能被填充两次)[1]虚拟继承的经典实现方法
Nope. Abstract methods implicitly are virtual.
Interface implementations do not need to be virtual. (In fact, it is possible to explicitely implement 'conflicting' interfaces (i.e. interfaces declaring identical member signatures). This would not be possible with the
vtable single dispatch
[1], because a single vtable slot cannot be filled twice)[1] classical implementation method for virtual inheritance
它们是隐式抽象的,因为它们没有定义行为,只描述了成员的签名。
我不知道 IL 是什么样子(实际上可能永远不需要知道)。
They are implicitly abstract in the sense that they have no behavior defined, only the signature of the member is described.
I don't know offhand what it looks like at the IL (and probably will never need to know, actually).