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 Determining Enclosing Instances 15.9.2<br />

direct subclass of the class named by T is declared. It is a compile-time error if<br />

the class denoted by T is a final class. If T denotes an interface then an anonymous<br />

direct subclass of Object that implements the interface named by T is<br />

declared. In either case, the body of the subclass is the ClassBody given in the<br />

class instance creation expression. <strong>The</strong> class being instantiated is the anonymous<br />

subclass.<br />

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

creation expression. Let T be the name of the Identifier after the new token. It<br />

is a compile-time error if T is not the simple name (§6.2) of an accessible<br />

(§6.6) non-final inner class (§8.1.3) that is a member of the compile-time<br />

type of the Primary. It is also a compile-time error if T is ambiguous (§8.5) or<br />

if T denotes an enum type. An anonymous direct subclass of the class named<br />

by T is declared. <strong>The</strong> body of the subclass is the ClassBody given in the class<br />

instance creation expression. <strong>The</strong> class being instantiated is the anonymous<br />

subclass.<br />

If a class instance creation expression does not declare an anonymous class,<br />

then:<br />

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

expression, then the ClassOrInterfaceType must denote a class that is<br />

accessible (§6.6) and is not an enum type and not abstract, or a compiletime<br />

error occurs. In this case, the class being instantiated is the class denoted<br />

by ClassOrInterfaceType.<br />

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

creation expression. It is a compile-time error if Identifier is not the simple<br />

name (§6.2) of an accessible (§6.6) non-abstract inner class (§8.1.3) T that<br />

is a member of the compile-time type of the Primary. It is also a compile-time<br />

error if Identifier is ambiguous (§8.5), or if Identifier denotes an enum type<br />

(§8.9). <strong>The</strong> class being instantiated is the class denoted by Identifier.<br />

<strong>The</strong> type of the class instance creation expression is the class type being<br />

instantiated.<br />

DRAFT<br />

15.9.2 Determining Enclosing Instances<br />

Let C be the class being instantiated, and let i the instance being created. If C is an<br />

inner class then i may have an immediately enclosing instance. <strong>The</strong> immediately<br />

enclosing instance of i (§8.1.3) is determined as follows:<br />

425

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

Saved successfully!

Ooh no, something went wrong!