What is the format of synthetic attributes in java?

While reading the oracle textbook (on reflection) of field modifiers, I came to the term "Synthetic attributes (fields)":

Please note that some fields are reported even if they are not declared in the source code. This is because the compiler generates some synthetic fields that are needed at runtime. To check if the field is synthetic, the example calls Field.isSynthetic ().

What is the structure or format of these synthetic fields or synthetic attributes in general?

+4
source share
1 answer

This is what I found in the JVM SE7 Specification

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. 
0
source

Source: https://habr.com/ru/post/1499917/


All Articles