ConstantValue属性用于表示field_info中的静态变量的初始值,结构如下:

    1. ConstantValue_attribute {
    2. u2 attribute_name_index;
    3. u4 attribute_length;
    4. u2 constantvalue_index;
    5. }

    ConstantValue解析代码片段:

    1. // 创建属性Map
    2. Map<String, Object> attrMap = new LinkedHashMap<>();
    3. // u2 constantvalue_index;
    4. attrMap.put("constantValue", getConstantPoolValue(dis.readUnsignedShort()));
    5. attributeMap.put("ConstantValue", attrMap);

    解析后的结果如下:

    1. {
    2. "access": 26,
    3. "name": "serialVersionUID",
    4. "desc": "J",
    5. "attributesCount": 1,
    6. "attributes": {
    7. "attributeName": "ConstantValue",
    8. "attributeLength": 2,
    9. "ConstantValue": {
    10. "constantValue": -7366591802115334000
    11. }
    12. }
    13. }