在阅读oracle教程(反思)字段修饰符时,我提到了合成属性( field )这个术语:
请注意,即使未在原始代码中声明某些字段,也会报告它们。这是因为编译器将生成运行时需要的一些合成字段。为了测试一个字段是否是合成的,该示例调用Field.isSynthetic()。
这些合成字段的结构或格式或一般的合成属性是什么?
发布于 2013-08-31 13:05:58
这就是我在JVM SE7规范中发现的
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.https://stackoverflow.com/questions/18547723
复制相似问题