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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

15.12 Method Invocation Expressions EXPRESSIONS<br />

440<br />

15.12 Method Invocation Expressions<br />

A method invocation expression is used to invoke a class or instance method.<br />

MethodInvocation:<br />

MethodName ( ArgumentListopt )<br />

Primary . NonWildTypeArgumentsopt Identifier ( ArgumentListopt )<br />

super . NonWildTypeArgumentsopt Identifier ( ArgumentListopt )<br />

ClassName . super . NonWildTypeArgumentsopt Identifier (<br />

ArgumentListopt )<br />

TypeName . NonWildTypeArguments Identifier ( ArgumentListopt )<br />

<strong>The</strong> definition of ArgumentList from §15.9 is repeated here for convenience:<br />

ArgumentList:<br />

Expression<br />

ArgumentList , Expression<br />

Resolving a method name at compile time is more complicated than resolving<br />

a field name because of the possibility of method overloading. Invoking a method<br />

at run time is also more complicated than accessing a field because of the possibility<br />

of instance method overriding.<br />

Determining the method that will be invoked by a method invocation expression<br />

involves several steps. <strong>The</strong> following three sections describe the compiletime<br />

processing of a method invocation; the determination of the type of the<br />

method invocation expression is described in §15.12.3.<br />

15.12.1 Compile-Time Step 1: Determine Class or Interface to Search<br />

<strong>The</strong> first step in processing a method invocation at compile time is to figure out<br />

the name of the method to be invoked and which class or interface to check for<br />

definitions of methods of that name. <strong>The</strong>re are several cases to consider, depending<br />

on the form that precedes the left parenthesis, as follows:<br />

• If the form is MethodName, then there are three subcases:<br />

DRAFT<br />

◆ If it is a simple name, that is, just an Identifier, then the name of the method<br />

is the Identifier. If the Identifier appears within the scope (§6.3) of a visible<br />

method declaration with that name, then there must be an enclosing type<br />

declaration of which that method is a member. Let T be the innermost such<br />

type declaration. <strong>The</strong> class or interface to search is T.<br />

◆ If it is a qualified name of the form TypeName . Identifier, then the name of<br />

the method is the Identifier and the class to search is the one named by the

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

Saved successfully!

Ooh no, something went wrong!