gpt4 book ai didi

Java .class 文件结构 - InnerClasses 属性

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:23:05 25 4
gpt4 key购买 nike

http://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.7.6

Every CONSTANT_Class_info entry in the constant_pool table which represents a class or interface C that is not a package member must have exactly one corresponding entry in the classes array.

类数组是 InnerClasses 属性的成员。

outer_class_info_index

If C is not a member of a class or an interface (that is, if C is a top-level class or interface (JLS §7.6) or a local class (JLS §14.3) or an anonymous class (JLS §15.9.5)), the value of the outer_class_info_index item must be zero.

问题:

在我看来,C 甚至可以是顶级类(正如前面的引文所说 -

"..that is, if C is a top-level class..."

但是如果第一个引文说,C 怎么可能是顶级类

"...class or interface C that is not a package member..."

“不是包成员”意味着类必须是嵌套的,对吧?所以它不可能是顶级类(class)。

最佳答案

我认为这是一个很好的语言律师案例。第一条声明是这样说的

Every CONSTANT_Class_info entry in the constant_pool table which represents a class or interface C that is not a package member must have exactly one corresponding entry in the classes array.

但是,它没有说顶级类不允许在类数组中有一个条目。

现在为什么它会有一个条目,我不知道。也许是为了将来的可扩展性。但是规范允许它,它会被实现忽略,因为它不是真正的内部/成员类。

所以这些陈述在技术上并不矛盾。

关于Java .class 文件结构 - InnerClasses 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26215075/

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