便于理解字节码,程序如下:
public class TextClass {
String name;
Integer age;
public TextClass(String name, Integer age) {
this.name = name;
this.age = age;
}
public void show(){
System.out.println("Hello MotherFucker");
}
}
编译后,用javap -verbose TextClass.class
反编译,得到如下
Classfile /C:/1/test/out/production/test/TextClass.class
Last modified 2021-7-31; size 660 bytes
MD5 checksum 9ab04c39930dc92a510f52caf49cfa0c
Compiled from "TextClass.java"
public class TextClass
minor version: 0
major version: 52
flags: ACC_PUBLIC, ACC_SUPER
Constant pool:
#1 = Methodref #8.#24 // java/lang/Object."<init>":()V
#2 = Fieldref #7.#25 // TextClass.name:Ljava/lang/String;
#3 = Fieldref #7.#26 // TextClass.age:Ljava/lang/Integer;
#4 = Fieldref #27.#28 // java/lang/System.out:Ljava/io/PrintStream;
#5 = String #29 // Hello MotherFucker
#6 = Methodref #30.#31 // java/io/PrintStream.println:(Ljava/lang/String;)V
#7 = Class #32 // TextClass
#8 = Class #33 // java/lang/Object
#9 = Utf8 name
#10 = Utf8 Ljava/lang/String;
#11 = Utf8 age
#12 = Utf8 Ljava/lang/Integer;
#13 = Utf8 <init>
#14 = Utf8 (Ljava/lang/String;Ljava/lang/Integer;)V
#15 = Utf8 Code
#16 = Utf8 LineNumberTable
#17 = Utf8 LocalVariableTable
#18 = Utf8 this
#19 = Utf8 LTextClass;
#20 = Utf8 show
#21 = Utf8 ()V
#22 = Utf8 SourceFile
#23 = Utf8 TextClass.java
#24 = NameAndType #13:#21 // "<init>":()V
#25 = NameAndType #9:#10 // name:Ljava/lang/String;
#26 = NameAndType #11:#12 // age:Ljava/lang/Integer;
#27 = Class #34 // java/lang/System
#28 = NameAndType #35:#36 // out:Ljava/io/PrintStream;
#29 = Utf8 Hello MotherFucker
#30 = Class #37 // java/io/PrintStream
#31 = NameAndType #38:#39 // println:(Ljava/lang/String;)V
#32 = Utf8 TextClass
#33 = Utf8 java/lang/Object
#34 = Utf8 java/lang/System
#35 = Utf8 out
#36 = Utf8 Ljava/io/PrintStream;
#37 = Utf8 java/io/PrintStream
#38 = Utf8 println
#39 = Utf8 (Ljava/lang/String;)V
{
java.lang.String name;
descriptor: Ljava/lang/String;
flags:
java.lang.Integer age;
descriptor: Ljava/lang/Integer;
flags:
public TextClass(java.lang.String, java.lang.Integer);
descriptor: (Ljava/lang/String;Ljava/lang/Integer;)V
flags: ACC_PUBLIC
Code:
stack=2, locals=3, args_size=3
0: aload_0
1: invokespecial #1 // Method java/lang/Object."<init>":()V
4: aload_0
5: aload_1
6: putfield #2 // Field name:Ljava/lang/String;
9: aload_0
10: aload_2
11: putfield #3 // Field age:Ljava/lang/Integer;
14: return
LineNumberTable:
line 9: 0
line 10: 4
line 11: 9
line 12: 14
LocalVariableTable:
Start Length Slot Name Signature
0 15 0 this LTextClass;
0 15 1 name Ljava/lang/String;
0 15 2 age Ljava/lang/Integer;
public void show();
descriptor: ()V
flags: ACC_PUBLIC
Code:
stack=2, locals=1, args_size=1
0: getstatic #4 // Field java/lang/System.out:Ljava/io/PrintStream;
3: ldc #5 // String Hello MotherFucker
5: invokevirtual #6 // Method java/io/PrintStream.println:(Ljava/lang/String;)V
8: return
LineNumberTable:
line 15: 0
line 16: 8
LocalVariableTable:
Start Length Slot Name Signature
0 9 0 this LTextClass;
}
SourceFile: "TextClass.java"