
數組類型特殊處理:
| Java 類型 | Class_info 存儲描述符 |
|---|---|
| Object | java/lang/Object |
| Object[] | [Ljava/lang/Object; |
| int[] | [I |
| int[][] | [[I |

構成:`class_index` + `name_and_type_index`
**符號引用本質** = 類信息 + 名稱類型信息
public class TestInt {
int a = 10;
void print() { System.out.println(a); }
}
反編譯常量池:
#1 = Class #2 // com/bjpowernode/test/TestInt
#2 = Utf8 com/bjpowernode/test/TestInt
#5 = Utf8 a
#6 = Utf8 I
#12 = Fieldref #1.#13 // com/bjpowernode/test/TestInt.a:I
#13 = NameAndType #5:#6 // a:I
// 字節碼
4: getfield #12 // Field a:I

鏈路:`getfield #12` → `Fieldref(#1, #13)` → `Class(#2)` + `NameAndType(#5, #6)` → `Utf8` 字符串。
public class Programer {
Computer computer;
public void doWork() { computer.calculate(); }
}
public class Computer {
public void calculate() { System.out.println("working..."); }
}
反編譯:
#12 = Utf8 ()V
#20 = Methodref #21.#23 // com/bjpowernode/test/Computer.calculate:()V
#21 = Class #22 // com/bjpowernode/test/Computer
#22 = Utf8 com/bjpowernode/test/Computer
#23 = NameAndType #24:#12 // calculate:()V
#24 = Utf8 calculate
// 字節碼
4: invokevirtual #20 // Method Computer.calculate:()V

public class Plane {
IFlyable flyable;
void flyToSky() { flyable.fly(); }
}
public interface IFlyable { void fly(); }
反編譯:
#8 = Utf8 ()V
#19 = InterfaceMethodref #20.#22 // com/bjpowernode/test/IFlyable.fly:()V
#20 = Class #21 // com/bjpowernode/test/IFlyable
#21 = Utf8 com/bjpowernode/test/IFlyable
#22 = NameAndType #23:#8 // fly:()V
#23 = Utf8 fly
// 字節碼
4: invokeinterface #19, 1 // InterfaceMethod IFlyable.fly:()V

| Tag | 類型 | 用途 | 核心索引 |
|---|---|---|---|
| 1 | CONSTANT_Utf8_info | UTF-8 字符串 | - |
| 3 | CONSTANT_Integer_info | int 常量 | - |
| 4 | CONSTANT_Float_info | float 常量 | - |
| 5 | CONSTANT_Long_info | long 常量(佔2槽) | - |
| 6 | CONSTANT_Double_info | double 常量(佔2槽) | - |
| 7 | CONSTANT_Class_info | 類/接口符號引用 | name_index → Utf8 |
| 8 | CONSTANT_String_info | 字符串字面量 | string_index → Utf8 |
| 9 | CONSTANT_Fieldref_info | 字段符號引用 | class_index + name_and_type_index |
| 10 | CONSTANT_Methodref_info | 類方法符號引用 | class_index + name_and_type_index |
| 11 | CONSTANT_InterfaceMethodref_info | 接口方法符號引用 | class_index + name_and_type_index |
| 12 | CONSTANT_NameAndType_info | 名稱+描述符 | name_index + descriptor_index → Utf8 |
下篇將解析常量池之後的結構:類信息、父類、接口、字段表、方法表、屬性表。