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.4 Run-time Evaluation of Class Instance Creation Expressions EXPRESSIONS<br />

428<br />

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

the first argument to the constructor, followed by the arguments in the<br />

argument list of the class instance creation expression, if any, in the order<br />

they appear in the expression.<br />

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

the constructor, in the order they appear in the expression.<br />

• Once the actual arguments have been determined, they are used to select a<br />

constructor of C, using the same rules as for method invocations (§15.12). As<br />

in method invocations, a compile-time method matching error results if there<br />

is no unique most-specific constructor that is both applicable and accessible.<br />

Note that the type of the class instance creation expression may be an anonymous<br />

class type, in which case the constructor being invoked is an anonymous<br />

constructor.<br />

15.9.4 Run-time Evaluation of Class Instance Creation Expressions<br />

At run time, evaluation of a class instance creation expression is as follows.<br />

First, if the class instance creation expression is a qualified class instance creation<br />

expression, the qualifying primary expression is evaluated. If the qualifying<br />

expression evaluates to null, aNullPointerException is raised, and the class<br />

instance creation expression completes abruptly. If the qualifying expression completes<br />

abruptly, the class instance creation expression completes abruptly for the<br />

same reason.<br />

Next, space is allocated for the new class instance. If there is insufficient<br />

space to allocate the object, evaluation of the class instance creation expression<br />

completes abruptly by throwing an OutOfMemoryError (§15.9.6).<br />

<strong>The</strong> new object contains new instances of all the fields declared in the specified<br />

class type and all its superclasses. As each new field instance is created, it is<br />

initialized to its default value (§4.12.5).<br />

Next, the actual arguments to the constructor are evaluated, left-to-right. If<br />

any of the argument evaluations completes abruptly, any argument expressions to<br />

its right are not evaluated, and the class instance creation expression completes<br />

abruptly for the same reason.<br />

Next, the selected constructor of the specified class type is invoked. This<br />

results in invoking at least one constructor for each superclass of the class type.<br />

This process can be directed by explicit constructor invocation statements (§8.8)<br />

and is described in detail in §12.5.<br />

DRAFT

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

Saved successfully!

Ooh no, something went wrong!