gpt4 book ai didi

java - 类的 "direct superinterface"是什么意思?

转载 作者:行者123 更新时间:2023-12-01 18:22:24 39 4
gpt4 key购买 nike

在 JLS 和 JVM 规范中,都有引用类的直接 super 接口(interface)的语言。类的直接 super 接口(interface)的概念令人困惑,因为类不能扩展接口(interface)。

例如,来自 JLS 第 9 节:

A class necessarily implements all the interfaces that its direct superclasses and direct superinterfaces do.

来自 JVM 规范第 5.4.3.2 节:

Otherwise, field lookup is applied recursively to the direct superinterfaces of the specified class or interface C.

尽管在 JLS 第 9.1.3 节中,直接 super 接口(interface)的定义如下

If an extends clause is provided, then the interface being declared extends each of the other named interfaces and therefore inherits the member types, methods, and constants of each of the other named interfaces. These other named interfaces are the direct superinterfaces of the interface being declared.

并严格表述为

Given a (possibly generic) interface declaration for I (n ≥ 0), the direct superinterfaces of the interface type I are the types given in the extends clause of the declaration of I if an extends clause is present.

在这两个定义中,直接 super 接口(interface)的概念应用于接口(interface)类型,而不是类类型。

那么类的直接 super 接口(interface)是什么意思?

最佳答案

直接 super 接口(interface)是类直接实现的所有接口(interface)。

例如,如果

类 X 实现 Y,Z

Y 和 Z 是 X 类的直接 super 接口(interface)。

除了实现其直接超接口(interface)之外,类还间接实现其直接父类(super class)实现的所有接口(interface)及其直接超接口(interface)扩展的所有接口(interface)。

JLS 8.1.5 :

The optional implements clause in a class declaration lists the names of interfaces that are direct superinterfaces of the class being declared.

关于java - 类的 "direct superinterface"是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27332255/

39 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com