Each field is described by a field_info structure.
No two fields in one class file may have the same name and descriptor (§4.3.2).
The structure has the following format:
field_info {
u2 access_flags;
u2 name_index;
u2 descriptor_index;
u2 attributes_count;
attribute_info attributes[attributes_count];
}
The items of the field_info structure are as follows:
-
access_flags
The value of the
access_flagsitem is a mask of flags used to denote access permission to and properties of this field. The interpretation of each flag, when set, is specified in Table 4.5-A.Table 4.5-A. Field access and property flags
Flag Name Value Interpretation ACC_PUBLIC0x0001 Declared public; may be accessed from outside its package.ACC_PRIVATE0x0002 Declared private; accessible only within the defining class and other classes belonging to the same nest (§5.4.4).ACC_PROTECTED0x0004 Declared protected; may be accessed within subclasses.ACC_STATIC0x0008 Declared static.ACC_FINAL0x0010 Declared final; never directly assigned to after object construction (JLS §17.5).ACC_VOLATILE0x0040 Declared volatile; cannot be cached.ACC_TRANSIENT0x0080 Declared transient; not written or read by a persistent object manager.ACC_SYNTHETIC0x1000 Declared synthetic; not present in the source code. ACC_ENUM0x4000 Declared as an element of an enum.Fields of classes may set any of the flags in Table 4.5-A. However, each field of a class may have at most one of its
ACC_PUBLIC,ACC_PRIVATE, andACC_PROTECTEDflags set (JLS §8.3.1), and must not have both itsACC_FINALandACC_VOLATILEflags set (JLS §8.3.1.4).Fields of interfaces must have their
ACC_PUBLIC,ACC_STATIC, andACC_FINALflags set; they may have theirACC_SYNTHETICflag set and must not have any of the other flags in Table 4.5-A set (JLS §9.3).The
ACC_SYNTHETICflag indicates that this field was generated by a compiler and does not appear in source code.The
ACC_ENUMflag indicates that this field is used to hold an element of an enumerated type.All bits of the
access_flagsitem not assigned in Table 4.5-A are reserved for future use. They should be set to zero in generatedclassfiles and should be ignored by Java Virtual Machine implementations. -
name_index
The value of the
name_indexitem must be a valid index into theconstant_pooltable. Theconstant_poolentry at that index must be aCONSTANT_Utf8_infostructure (§4.4.7) which represents a valid unqualified name denoting a field (§4.2.2). -
descriptor_index
The value of the
descriptor_indexitem must be a valid index into theconstant_pooltable. Theconstant_poolentry at that index must be aCONSTANT_Utf8_infostructure (§4.4.7) which represents a valid field descriptor (§4.3.2). -
attributes_count
The value of the
attributes_countitem indicates the number of additional attributes of this field. -
attributes[]
Each value of the
attributestable must be anattribute_infostructure (§4.7).A field can have any number of optional attributes associated with it.
The attributes defined by this specification as appearing in the
attributestable of afield_infostructure are listed in Table 4.7-C.The rules concerning attributes defined to appear in the
attributestable of afield_infostructure are given in §4.7.The rules concerning non-predefined attributes in the
attributestable of afield_infostructure are given in §4.7.1.