This question already has an answer here:
这个问题在这里已有答案:
- Reading a Java bytecode instruction: What does the number mean? 2 answers
- 读取Java字节码指令:数字是什么意思? 2个答案
I wrote a simple java source like this :
我写了一个简单的java源代码:
public class Main {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
and converted it to the equivalent bytecode with the javap -c command
并使用javap -c命令将其转换为等效的字节码
Compiled from "Main.java"
public class Main {
public Main();
Code:
0: aload_0
1: invokespecial #1 // Method java/lang/Object."<init>":()V
4: return
public static void main(java.lang.String[]);
Code:
0: getstatic #2 // Field java/lang/System.out:Ljava/io/PrintStream;
3: ldc #3 // String Hello World!
5: invokevirtual #4 // Method java/io/PrintStream.println:(Ljava/lang/String;)V
8: return
}
What are #1,#2,#3,#4,... ?
什么是#1,#2,#3,#4,......?
When and Why would you use it ?
何时以及为何使用它?
2 个解决方案
#1
4
Those #
symbols refer to the constant pool of the class, if you decompile verbosely using
如果你使用verbosely反编译,那些#符号引用类的常量池
javap -c -s -verbose Main.class
you will get their definition in the Constant pool
section
您将在常量池部分中获得它们的定义
Constant pool:
#1 = Methodref #6.#15 // java/lang/Object."<init>"()V
#2 = Fieldref #16.#17 //
= String #18 // Hello World!
#4 = Methodref #19.#20 // java/io/PrintStream.println:(Ljava/lang/String;)V
#5 = Class #21 // Main
#6 = Class #22 // java/lang/Object
#7 = Utf8 <init>
#8 = Utf8 ()V
#9 = Utf8 Code
#10 = Utf8 LineNumberTable
#11 = Utf8 main
...
#2
1
The #x
refers to an entry in the class constant pool. The actual value of the entry is printed in the comment.
#x引用类常量池中的条目。条目的实际值将打印在注释中。
To also view the constant pool use javap -c -verbose ...
要查看常量池,请使用javap -c -verbose ...
#1
4
Those #
symbols refer to the constant pool of the class, if you decompile verbosely using
如果你使用verbosely反编译,那些#符号引用类的常量池
javap -c -s -verbose Main.class
you will get their definition in the Constant pool
section
您将在常量池部分中获得它们的定义
Constant pool:
#1 = Methodref #6.#15 // java/lang/Object."<init>"()V
#2 = Fieldref #16.#17 //
= String #18 // Hello World!
#4 = Methodref #19.#20 // java/io/PrintStream.println:(Ljava/lang/String;)V
#5 = Class #21 // Main
#6 = Class #22 // java/lang/Object
#7 = Utf8 <init>
#8 = Utf8 ()V
#9 = Utf8 Code
#10 = Utf8 LineNumberTable
#11 = Utf8 main
...
#2
1
The #x
refers to an entry in the class constant pool. The actual value of the entry is printed in the comment.
#x引用类常量池中的条目。条目的实际值将打印在注释中。
To also view the constant pool use javap -c -verbose ...
要查看常量池,请使用javap -c -verbose ...