在阅读字段修饰符的oracle教程(关于反射)时,我出现了术语合成属性(字段):
请注意,即使未声明某些字段,也会报告这些字段 在原始代码中。这是因为编译器会生成一些 运行时期间需要的合成字段。要测试是否一个 field是合成的,该示例调用Field.isSynthetic()。
这些合成字段的结构或格式或一般合成属性是什么?
答案 0 :(得分:0)
The Synthetic attribute is a fixed-length attribute in the attributes
table of a ClassFile, field_info, or method_info structure (§4.1,
§4.5, §4.6). A class member that does not appear in the source code
must be marked using a Synthetic attribute, or else it must have its
ACC_SYNTHETIC flag set. The only exceptions to this requirement are
compiler-generated methods which are not considered implementation
artifacts, namely the instance initialization method representing a
default constructor of the Java programming language (§2.9), the class
initialization method (§2.9), and the Enum.values() and Enum.valueOf()
methods.
The Synthetic attribute was introduced in JDK release 1.1 to support
nested classes and interfaces.
The Synthetic attribute has the following format:
Synthetic_attribute {
u2 attribute_name_index;
u4 attribute_length;
}
The items of the Synthetic_attribute structure are as follows:
attribute_name_index
The value of the attribute_name_index item must be a valid index into
the constant_pool table. The constant_pool entry at that index must be
a CONSTANT_Utf8_info (§4.4.7) structure representing the string "Synthetic".
attribute_length
The value of the attribute_length item is zero.