Each method, including each instance initialization method (§2.9) and the class or interface initialization method (§2.9), 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_flags
item 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 flagsFlag NameValueInterpretationACC_PUBLIC
0x0001Declaredpublic
; may be accessed from outside its package.ACC_PRIVATE
0x0002Declaredprivate
; accessible only within the defining class.ACC_PROTECTED
0x0004Declaredprotected
; may be accessed within subclasses.ACC_STATIC
0x0008Declaredstatic
.ACC_FINAL
0x0010Declaredfinal
; must not be overridden (§5.4.5).ACC_SYNCHRONIZED
0x0020Declaredsynchronized
; invocation is wrapped by a monitor use.ACC_BRIDGE
0x0040A bridge method, generated by the compiler.ACC_VARARGS
0x0080Declared with variable number of arguments.ACC_NATIVE
0x0100Declarednative
; implemented in a language other than Java.ACC_ABSTRACT
0x0400Declaredabstract
; no implementation is provided.ACC_STRICT
0x0800Declaredstrictfp
; floating-point mode is FP-strict.ACC_SYNTHETIC
0x1000Declared synthetic; not present in the source code.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 itsACC_PUBLIC
,ACC_PRIVATE
, andACC_PROTECTED
flags set (JLS §8.4.3).Methods of interfaces may have any of the flags in Table 4.6-A set exceptACC_PROTECTED
,ACC_FINAL
,ACC_SYNCHRONIZED
, andACC_NATIVE
(JLS §9.4). In aclass
file whose version number is less than 52.0, each method of an interface must have itsACC_PUBLIC
andACC_ABSTRACT
flags set; in aclass
file whose version number is 52.0 or above, each method of an interface must have exactly one of itsACC_PUBLIC
andACC_PRIVATE
flags set.If a method of a class or interface has itsACC_ABSTRACT
flag set, it must not have any of itsACC_PRIVATE
,ACC_STATIC
,ACC_FINAL
,ACC_SYNCHRONIZED
,ACC_NATIVE
, orACC_STRICT
flags set.Each instance initialization method (§2.9) may have at most one of itsACC_PUBLIC
,ACC_PRIVATE
, andACC_PROTECTED
flags set, and may also have itsACC_VARARGS
,ACC_STRICT
, andACC_SYNTHETIC
flags set, but must not have any of the other flags in Table 4.6-A set.Class and interface initialization methods are called implicitly by the Java Virtual Machine. The value of theiraccess_flags
item is ignored except for the setting of theACC_STRICT
flag.TheACC_BRIDGE
flag is used to indicate a bridge method generated by a compiler for the Java programming language.TheACC_VARARGS
flag 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_VARARGS
flag set to 1. All other methods must be compiled with theACC_VARARGS
flag set to 0.TheACC_SYNTHETIC
flag 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 theaccess_flags
item not assigned in Table 4.6-A are reserved for future use. They should be set to zero in generatedclass
files and should be ignored by Java Virtual Machine implementations. -
name_index
The value of the
name_index
item must be a valid index into theconstant_pool
table. Theconstant_pool
entry at that index must be aCONSTANT_Utf8_info
structure (§4.4.7) representing either one of the special method names<init>
or<clinit>
(§2.9), or a valid unqualified name denoting a method (§4.2.2). -
descriptor_index
The value of the
descriptor_index
item must be a valid index into theconstant_pool
table. Theconstant_pool
entry at that index must be aCONSTANT_Utf8_info
structure representing a valid method descriptor (§4.3.3).A future edition of this specification may require that the last parameter descriptor of the method descriptor is an array type if theACC_VARARGS
flag is set in theaccess_flags
item. -
attributes_count
The value of the
attributes_count
item indicates the number of additional attributes of this method. -
attributes[]
Each value of the
attributes
table must be anattribute_info
structure (§4.7).A method can have any number of optional attributes associated with it.The attributes defined by this specification as appearing in theattributes
table of amethod_info
structure are listed in Table 4.7-C.The rules concerning attributes defined to appear in theattributes
table of amethod_info
structure are given in §4.7.The rules concerning non-predefined attributes in theattributes
table of amethod_info
structure are given in §4.7.1.