The MethodParameters attribute is a variable-length attribute in the attributes table of a method_info structure (§4.6). A MethodParameters attribute records information about the formal parameters of a method, such as their names.
There may be at most one MethodParameters attribute in the attributes table of a method_info structure.
The MethodParameters attribute has the following format:
MethodParameters_attribute {
u2 attribute_name_index;
u4 attribute_length;
u1 parameters_count;
{ u2 name_index;
u2 access_flags;
} parameters[parameters_count];
}
The items of the MethodParameters_attribute structure are as follows:
-
attribute_name_index
The value of the
attribute_name_indexitem must be a valid index into theconstant_pooltable. Theconstant_poolentry at that index must be aCONSTANT_Utf8_infostructure representing the string "MethodParameters". -
attribute_length
The value of the
attribute_lengthitem indicates the length of the attribute, excluding the initial six bytes. -
parameters_count
The value of the
parameters_countitem indicates the number of parameter descriptors in the method descriptor (§4.3.3) referenced by thedescriptor_indexof the attribute's enclosingmethod_infostructure.This is not a constraint which a Java Virtual Machine implementation must enforce during format checking (§4.8). The task of matching parameter descriptors in a method descriptor against the items in the
parametersarray below is done by the reflection libraries of the Java SE platform. -
parameters[]
Each entry in the
parametersarray contains the following pair of items:-
name_index
The value of the
name_indexitem must either be zero or a valid index into theconstant_pooltable.If the value of the
name_indexitem is zero, then thisparameterselement indicates a formal parameter with no name.If the value of the
name_indexitem is nonzero, theconstant_poolentry at that index must be aCONSTANT_Utf8_infostructure representing a valid unqualified name denoting a formal parameter (§4.2.2). -
access_flags
The value of the
access_flagsitem is as follows:-
0x0010 (
ACC_FINAL)Indicates that the formal parameter was declared
final. -
0x1000 (
ACC_SYNTHETIC)Indicates that the formal parameter was not explicitly or implicitly declared in source code, according to the specification of the language in which the source code was written (JLS §13.1). (The formal parameter is an implementation artifact of the compiler which produced this
classfile.) -
0x8000 (
ACC_MANDATED)Indicates that the formal parameter was implicitly declared in source code, according to the specification of the language in which the source code was written (JLS §13.1). (The formal parameter is mandated by a language specification, so all compilers for the language must emit it.)
-
-
The i'th entry in the parameters array corresponds to the i'th parameter descriptor in the enclosing method's descriptor. (The parameters_count item is one byte because a method descriptor is limited to 255 parameters.) Effectively, this means the parameters array stores information for all the parameters of the method. One could imagine other schemes, where entries in the parameters array specify their corresponding parameter descriptors, but it would unduly complicate the MethodParameters attribute.
The i'th entry in the parameters array may or may not correspond to the i'th type in the enclosing method's Signature attribute (if present), or to the i'th annotation in the enclosing method's parameter annotations.