Java Reference
In-Depth Information
// ok - occurs in a different class
int j;
}
8.4. Method Declarations
A method declares executable code that can be invoked, passing a fixed number of values
as arguments.
MethodDeclaration:
MethodHeader MethodBody
MethodHeader:
MethodModifiers opt TypeParameters opt Result MethodDeclarator Throws opt
MethodDeclarator:
Identifier ( FormalParameterList opt )
The FormalParameterList is described in § 8.4.1 , the MethodModifiers clause in § 8.4.3 , the
TypeParameters clause in § 8.4.4 , the Result clause in § 8.4.5 , the Throws clause in § 8.4.6 ,
and the MethodBody in § 8.4.7 .
The Identifier in a MethodDeclarator may be used in a name to refer to the method.
It is a compile-time error for the body of a class to declare as members two methods with
override-equivalent signatures (§ 8.4.2 ).
The scope and shadowing of a method declaration is specified in § 6.3 and § 6.4 .
For compatibility with older versions of the Java SE platform, the declaration of a method
that returns an array is allowed to place (some or all of) the empty bracket pairs that form
the declaration of the array type after the formal parameter list. This is supported by the
following obsolescent production, but should not be used in new code.
MethodDeclarator:
MethodDeclarator [ ]
8.4.1. Formal Parameters
The formal parameters of a method or constructor, if any, are specified by a list of comma-
separated parameter specifiers. Each parameter specifier consists of a type (optionally pre-
ceded by the final modifier and/or one or more annotations) and an identifier (optionally
followed by brackets) that specifies the name of the parameter.
Search WWH ::




Custom Search