查看在某些类上运行 javap
的输出,我遇到了以下奇怪的事情:
某些类的常量池包含条目如
#33 = Utf8 Code
#34 = Utf8 LocalVariableTable
#35 = Utf8 StackMapTable
#36 = Utf8 MethodParameters
为什么这些常量会出现在常量池中?
最佳答案
以下常量
#33 = Utf8 Code
#34 = Utf8 LocalVariableTable
#35 = Utf8 StackMapTable
#36 = Utf8 MethodParameters
是attributes的名称.
For all attributes, the attribute_name_index must be a valid unsigned 16-bit index into the constant pool of the class. The constant_pool entry at attribute_name_index must be a CONSTANT_Utf8_info structure (§4.4.7) representing the name of the attribute.
您提到的属性具有以下功能:
Code
属性包含 Java 虚拟机指令和方法的辅助信息,包括实例初始化方法或类或接口(interface)初始化方法。- 调试器可以使用
LocalVariableTable
属性 [...] 在方法执行期间确定给定局部变量的值。 StackMapTable
属性用于类型检查验证过程MethodParameters
属性记录有关方法形式参数的信息,例如它们的名称。
关于java - JVM 常量池条目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28768333/