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.

EXPRESSIONS Runtime Evaluation of Method Invocation 15.12.4<br />

◆ If the compile-time declaration has the static modifier, then the invocation<br />

mode is static.<br />

◆ Otherwise, if the compile-time declaration has the private modifier, then<br />

the invocation mode is nonvirtual.<br />

◆ Otherwise, if the part of the method invocation before the left parenthesis is<br />

of the form super . Identifier or of the form ClassName.super.Identifier<br />

then the invocation mode is super.<br />

◆ Otherwise, if the compile-time declaration is in an interface, then the invocation<br />

mode is interface.<br />

◆ Otherwise, the invocation mode is virtual.<br />

If the compile-time declaration for the method invocation is not void, then<br />

the type of the method invocation expression is the result type specified in the<br />

compile-time declaration.<br />

15.12.4 Runtime Evaluation of Method Invocation<br />

At run time, method invocation requires five steps. First, a target reference may be<br />

computed. Second, the argument expressions are evaluated. <strong>Third</strong>, the accessibility<br />

of the method to be invoked is checked. Fourth, the actual code for the method<br />

to be executed is located. Fifth, a new activation frame is created, synchronization<br />

is performed if necessary, and control is transferred to the method code.<br />

15.12.4.1 Compute Target Reference (If Necessary)<br />

<strong>The</strong>re are several cases to consider, depending on which of the five productions<br />

for MethodInvocation (§15.12) is involved:<br />

• If the first production for MethodInvocation, which includes a MethodName,<br />

is involved, then there are three subcases:<br />

DRAFT<br />

◆ If the MethodName is a simple name, that is, just an Identifier, then there are<br />

two subcases:<br />

❖ If the invocation mode is static, then there is no target reference.<br />

❖ Otherwise, let T be the enclosing type declaration of which the method is<br />

a member, and let n be an integer such that T is the nth lexically enclosing<br />

type declaration (§8.1.3) of the class whose declaration immediately contains<br />

the method invocation. <strong>The</strong>n the target reference is the nth lexically<br />

enclosing instance (§8.1.3) of this. It is a compile-time error if the nth<br />

lexically enclosing instance (§8.1.3) of this does not exist.<br />

473

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

Saved successfully!

Ooh no, something went wrong!