ConstantValue
属性用于表示field_info
中的静态变量的初始值,结构如下:
ConstantValue_attribute {
u2 attribute_name_index;
u4 attribute_length;
u2 constantvalue_index;
}
ConstantValue解析代码片段:
// 创建属性Map
Map<String, Object> attrMap = new LinkedHashMap<>();
// u2 constantvalue_index;
attrMap.put("constantValue", getConstantPoolValue(dis.readUnsignedShort()));
attributeMap.put("ConstantValue", attrMap);
解析后的结果如下:
{
"access": 26,
"name": "serialVersionUID",
"desc": "J",
"attributesCount": 1,
"attributes": {
"attributeName": "ConstantValue",
"attributeLength": 2,
"ConstantValue": {
"constantValue": -7366591802115334000
}
}
}