JVM Knowledge

A method declares executable code that can be invoked, passing a fixed number of values as arguments.

MethodDeclaration:
  {MethodModifier} MethodHeader MethodBody

MethodHeader:
  Result MethodDeclarator [Throws]
  TypeParameters {Annotation} Result MethodDeclarator [Throws]

MethodDeclarator:
  Identifier ( [FormalParameterList] ) [Dims]

The following production from §4.3 is shown here for convenience:

Dims:
  {Annotation} [ ] {{Annotation} [ ]}

The FormalParameterList is described in §8.4.1, the MethodModifier 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 (§6.5.7.1, §15.12).

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.

The declaration of a method that returns an array is allowed to place some or all of the bracket pairs that denote the array type after the formal parameter list. This syntax is supported for compatibility with early versions of the Java programming language. It is very strongly recommended that this syntax is not used in new code.

Sections: