繼字段表集合之後,Class 文件結構進入方法表集合區域。方法表描述類/接口中聲明的所有方法(含構造函數、靜態方法等),結構與字段表高度相似,但屬性表中包含關鍵的 Code 屬性(存放字節碼指令)。
| 類型 | 名稱 | 數量 |
|---|---|---|
| u2 | access_flags | 1 |
| u2 | name_index | 1 |
| u2 | descriptor_index | 1 |
| u2 | attributes_count | 1 |
| attribute_info | attributes | attributes_count |
| 標志名稱 | 標志值 | 含義 |
|---|---|---|
| ACC_PUBLIC | 0x0001 | public |
| ACC_PRIVATE | 0x0002 | private |
| ACC_PROTECTED | 0x0004 | protected |
| ACC_STATIC | 0x0008 | static |
| ACC_FINAL | 0x0010 | final |
| ACC_SYNCHRONIZED | 0x0020 | synchronized |
| ACC_BRIDGE | 0x0040 | 橋接方法 |
| ACC_VARARGS | 0x0080 | 可變參數 |
| ACC_NATIVE | 0x0100 | native |
| ACC_ABSTRACT | 0x0400 | abstract |
| ACC_STRICTFP | 0x0800 | strictfp |
| ACC_SYNTHETIC | 0x1000 | 編譯器生成 |
某 Class 文件方法表區域十六進制片段:
0x00 02 // methods_count = 2 // 方法 1 0x00 01 // access_flags = ACC_PUBLIC 0x00 07 // name_index = #7 → "<init>" 0x00 08 // descriptor_index = #8 → "()V" 0x00 01 // attributes_count = 1 0x00 09 // attribute_name_index = #9 → "Code" // 方法 2 ...(省略)
對應源碼含一個公共無參構造函數,解析吻合。


