10.12.2012 Views

The Java Language Specification, Third Edition

The Java Language Specification, Third Edition

The Java Language Specification, Third Edition

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

8.4.1 Formal Parameters CLASSES<br />

210<br />

MethodDeclaration:<br />

MethodHeader MethodBody<br />

MethodHeader:<br />

MethodModifiersopt TypeParametersopt ResultType MethodDeclarator<br />

Throws opt<br />

ResultType:<br />

Type<br />

void<br />

MethodDeclarator:<br />

Identifier ( FormalParameterListopt )<br />

<strong>The</strong> MethodModifiers are described in §8.4.3, the TypeParameters clause of a<br />

method in §8.4.4, the Throws clause in §8.4.6, and the MethodBody in §8.4.7. A<br />

method declaration either specifies the type of value that the method returns or<br />

uses the keyword void to indicate that the method does not return a value.<br />

<strong>The</strong> Identifier in a MethodDeclarator may be used in a name to refer to the<br />

method. A class can declare a method with the same name as the class or a field,<br />

member class or member interface of the class, but this is discouraged as a matter<br />

of syle.<br />

For compatibility with older versions of the <strong>Java</strong> platform, a declaration form<br />

for a method that returns an array is allowed to place (some or all of) the empty<br />

bracket pairs that form the declaration of the array type after the parameter list.<br />

This is supported by the obsolescent production:<br />

MethodDeclarator:<br />

MethodDeclarator [ ]<br />

but should not be used in new code.<br />

It is a compile-time error for the body of a class to declare as members two<br />

methods with override-equivalent signatures (§8.4.2) (name, number of parameters,<br />

and types of any parameters). Methods and fields may have the same name,<br />

since they are used in different contexts and are disambiguated by different lookup<br />

procedures (§6.5).<br />

8.4.1 Formal Parameters<br />

DRAFT<br />

<strong>The</strong> formal parameters of a method or constructor, if any, are specified by a list of<br />

comma-separated parameter specifiers. Each parameter specifier consists of a type<br />

(optionally preceded by the final modifier and/or one or more annotations<br />

(§9.7)) and an identifier (optionally followed by brackets) that specifies the name

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!