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.

EXPRESSIONS Choosing the Constructor and its Arguments 15.9.3<br />

• If S is a local class (§14.3), then let O be the innermost lexically enclosing<br />

class of S. Let n be an integer such that O is the nth lexically enclosing class<br />

of the class in which the class instance creation expression appears. <strong>The</strong>n:<br />

◆ If S occurs within a static context, then i has no immediately enclosing<br />

instance with respect to S.<br />

◆ Otherwise, if the class instance creation expression occurs in a static context,<br />

then a compile-time error occurs.<br />

◆ Otherwise, the immediately enclosing instance of i with respect to S is the<br />

nth lexically enclosing instance of this.<br />

• Otherwise, S is an inner member class (§8.5).<br />

◆ If the class instance creation expression is an unqualified class instance creation<br />

expression, then:<br />

❖ If the class instance creation expression occurs in a static context, then a<br />

compile-time error occurs.<br />

❖ Otherwise, if S is a member of an enclosing class then let O be the innermost<br />

lexically enclosing class of which S is a member, and let n be an<br />

integer such that O is the nth lexically enclosing class of the class in which<br />

the class instance creation expression appears. <strong>The</strong> immediately enclosing<br />

instance of i with respect to S is the nth lexically enclosing instance of<br />

this.<br />

❖ Otherwise, a compile-time error occurs.<br />

◆ Otherwise, the class instance creation expression is a qualified class<br />

instance creation expression. <strong>The</strong> immediately enclosing instance of i with<br />

respect to S is the object that is the value of the Primary expression.<br />

DRAFT<br />

15.9.3 Choosing the Constructor and its Arguments<br />

Let C be the class type being instantiated. To create an instance of C, i, a constructor<br />

of C is chosen at compile-time by the following rules:<br />

• First, the actual arguments to the constructor invocation are determined.<br />

◆ If C is an anonymous class, and the direct superclass of C, S, is an inner<br />

class, then:<br />

❖ If the S is a local class and S occurs in a static context, then the arguments<br />

in the argument list, if any, are the arguments to the constructor, in the<br />

order they appear in the expression.<br />

427

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

Saved successfully!

Ooh no, something went wrong!