Each method, including each instance initialization method (§2.9.1) and the class or interface initialization method (§2.9.2), is described by a method_info structure.
No two methods in one class file may have the same name and descriptor (§4.3.3).
The structure has the following format:
method_info {
u2 access_flags;
u2 name_index;
u2 descriptor_index;
u2 attributes_count;
attribute_info attributes[attributes_count];
}
The items of the method_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 method. The interpretation of each flag, when set, is specified in Table 4.6-A.Table 4.6-A. Method 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; must not be overridden (§5.4.5).ACC_SYNCHRONIZED0x0020 Declared synchronized; invocation is wrapped by a monitor use.ACC_BRIDGE0x0040 A bridge method, generated by the compiler. ACC_VARARGS0x0080 Declared with variable number of arguments. ACC_NATIVE0x0100 Declared native; implemented in a language other than the Java programming language.ACC_ABSTRACT0x0400 Declared abstract; no implementation is provided.ACC_STRICT0x0800 In a classfile whose major version number is at least 46 and at most 60: Declaredstrictfp.ACC_SYNTHETIC0x1000 Declared synthetic; not present in the source code. The value 0x0800 is interpreted as the
ACC_STRICTflag only in aclassfile whose major version number is at least 46 and at most 60. For methods in such aclassfile, the rules below determine whether theACC_STRICTflag may be set in combination with other flags. (Setting theACC_STRICTflag constrained a method's floating-point instructions in Java SE 1.2 through 16 (§2.8).) For methods in aclassfile whose major version number is less than 46 or greater than 60, the value 0x0800 is not interpreted as theACC_STRICTflag, but rather is unassigned; it is not meaningful to "set theACC_STRICTflag" in such aclassfile.Methods of classes may have any of the flags in Table 4.6-A set. However, each method of a class may have at most one of its
ACC_PUBLIC,ACC_PRIVATE, andACC_PROTECTEDflags set (JLS §8.4.3).Methods of interfaces may have any of the flags in Table 4.6-A set except
ACC_PROTECTED,ACC_FINAL,ACC_SYNCHRONIZED, andACC_NATIVE(JLS §9.4). In aclassfile whose version number is less than 52.0, each method of an interface must have itsACC_PUBLICandACC_ABSTRACTflags set; in aclassfile whose version number is 52.0 or above, each method of an interface must have exactly one of itsACC_PUBLICandACC_PRIVATEflags set.If a method of a class or interface has its
ACC_ABSTRACTflag set, it must not have any of itsACC_PRIVATE,ACC_STATIC,ACC_FINAL,ACC_SYNCHRONIZED, orACC_NATIVEflags set, nor (in aclassfile whose major version number is at least 46 and at most 60) have itsACC_STRICTflag set.An instance initialization method (§2.9.1) may have at most one of its
ACC_PUBLIC,ACC_PRIVATE, andACC_PROTECTEDflags set, and may also have itsACC_VARARGSandACC_SYNTHETICflags set, and may also (in aclassfile whose major version number is at least 46 and at most 60) have itsACC_STRICTflag set, but must not have any of the other flags in Table 4.6-A set.In a
classfile whose version number is 51.0 or above, a method whose name is<clinit>must have itsACC_STATICflag set.A class or interface initialization method (§2.9.2) is called implicitly by the Java Virtual Machine. The value of its
access_flagsitem is ignored except for the setting of theACC_STATICflag and (in aclassfile whose major version number is at least 46 and at most 60) theACC_STRICTflag, and the method is exempt from the preceding rules about legal combinations of flags.The
ACC_BRIDGEflag is used to indicate a bridge method generated by a compiler for the Java programming language.The
ACC_VARARGSflag indicates that this method takes a variable number of arguments at the source code level. A method declared to take a variable number of arguments must be compiled with theACC_VARARGSflag set to 1. All other methods must be compiled with theACC_VARARGSflag set to 0.The
ACC_SYNTHETICflag indicates that this method was generated by a compiler and does not appear in source code, unless it is one of the methods named in §4.7.8.All bits of the
access_flagsitem not assigned in Table 4.6-A are reserved for future use. (This includes the bit corresponding to 0x0800 in aclassfile whose major version number is less than 46 or greater than 60.) 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) representing either a valid unqualified name denoting a method (§4.2.2), or (if this method is in a class rather than an interface) the special method name<init>, or the special method name<clinit>. -
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 representing a valid method descriptor (§4.3.3). Furthermore:- If this method is in a class rather than an interface, and the name of the method is
<init>, then the descriptor must denote avoidmethod. - If the name of the method is
<clinit>, then the descriptor must denote avoidmethod, and, in aclassfile whose version number is 51.0 or above, a method that takes no arguments.
A future edition of this specification may require that the last parameter descriptor of the method descriptor is an array type if the
ACC_VARARGSflag is set in theaccess_flagsitem. - If this method is in a class rather than an interface, and the name of the method is
-
attributes_count
The value of the
attributes_countitem indicates the number of additional attributes of this method. -
attributes[]
Each value of the
attributestable must be anattribute_infostructure (§4.7).A method can have any number of optional attributes associated with it.
The attributes defined by this specification as appearing in the
attributestable of amethod_infostructure are listed in Table 4.7-C.The rules concerning attributes defined to appear in the
attributestable of amethod_infostructure are given in §4.7.The rules concerning non-predefined attributes in the
attributestable of amethod_infostructure are given in §4.7.1.