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.

15.9.1 Determining the Class being Instantiated EXPRESSIONS<br />

424<br />

generic constructor (§8.8.4)). <strong>The</strong> type arguments to the constructor immediately<br />

follow the keyword new. It is a compile-time error if any of the type arguments<br />

used in a class instance creation expression are wildcard type arguments (§4.5.1).<br />

Class instance creation expressions have two forms:<br />

• Unqualified class instance creation expressions begin with the keyword new.<br />

An unqualified class instance creation expression may be used to create an<br />

instance of a class, regardless of whether the class is a top-level (§7.6), member<br />

(§8.5, §9.5), local (§14.3) or anonymous class (§15.9.5).<br />

• Qualified class instance creation expressions begin with a Primary. A qualified<br />

class instance creation expression enables the creation of instances of<br />

inner member classes and their anonymous subclasses.<br />

A class instance creation expression can throw an exception type E iff either:<br />

• <strong>The</strong> expression is a qualified class instance creation expression and the qualifying<br />

expression can throw E; or<br />

• Some expression of the argument list can throw E; or<br />

• E is listed in the throws clause of the type of the constructor that is invoked; or<br />

• <strong>The</strong> class instance creation expression includes a ClassBody, and some instnance<br />

initializer block or instance variable initializer expression in the Class-<br />

Body can throw E.<br />

Both unqualified and qualified class instance creation expressions may<br />

optionally end with a class body. Such a class instance creation expression<br />

declares an anonymous class (§15.9.5) and creates an instance of it.<br />

We say that a class is instantiated when an instance of the class is created by a<br />

class instance creation expression. Class instantiation involves determining what<br />

class is to be instantiated, what the enclosing instances (if any) of the newly created<br />

instance are, what constructor should be invoked to create the new instance<br />

and what arguments should be passed to that constructor.<br />

DRAFT<br />

15.9.1 Determining the Class being Instantiated<br />

If the class instance creation expression ends in a class body, then the class being<br />

instantiated is an anonymous class. <strong>The</strong>n:<br />

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

expression, then let T be the ClassOrInterfaceType after the new token. It<br />

is a compile-time error if the class or interface named by T is not accessible<br />

(§6.6) or if T is an enum type (§8.9). If T denotes a class, then an anonymous

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

Saved successfully!

Ooh no, something went wrong!