gpt4 book ai didi

java - 字节码如何表示另一个类

转载 作者:行者123 更新时间:2023-11-30 04:19:29 25 4
gpt4 key购买 nike

如果我有这些文件:

//Gizmo.java
public class Gizmo {
public static void main(String[] args) {
Gadget g = new Gadget();
}
}

.

//Gadget.java
public class Gadget {
public static void main(String[] args) {
System.out.println("hello world");
}
}

我用javac Gizmo.java Gadget.java编译它们,然后我有一个问题。 Gizmo.class 文件如何引用“Gadget”类?文件中的某处是否只有一个字符串“Gadget”?

最佳答案

您的答案位于 JLS4.2.1 的以下行中其中说:

Class and interface names that appear in class file structures are always represented in a fully qualified form known as binary names (JLS §13.1). Such names are always represented as CONSTANT_Utf8_info structures (§4.4.7) and thus may be drawn, where not further constrained, from the entire Unicode codespace. Class and interface names are referenced from those CONSTANT_NameAndType_info structures (§4.4.6) which have such names as part of their descriptor (§4.3), and from all CONSTANT_Class_info structures (§4.4.1).

For historical reasons, the syntax of binary names that appear in class file structures differs from the syntax of binary names documented in JLS §13.1. In this internal form, the ASCII periods (.) that normally separate the identifiers which make up the binary name are replaced by ASCII forward slashes (/). The identifiers themselves must be unqualified names (§4.2.2).

关于java - 字节码如何表示另一个类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17456599/

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