Java Reference
In-Depth Information
Let T be the type denoted by C followed by any class type arguments in the ex-
pression. The process described in § 15.12.2 , modified to handle constructors, is
used to select one of the constructors of T and determine its throws clause.
As in method invocations, it is a compile-time error if there is no unique most-spe-
cific constructor that is both applicable and accessible.
Otherwise, the result type is T .
Finally, the type of the class instance creation expression is the result type of the chosen
constructor, as defined above.
Note that the type of the class instance creation expression may be an anonymous class
type, in which case the constructor being invoked is an anonymous constructor (§ 15.9.5.1 ) .
15.9.4. Run-Time Evaluation of Class Instance Creation Expressions
At run time, evaluation of a class instance creation expression is as follows.
First, if the class instance creation expression is a qualified class instance creation expres-
sion, the qualifying primary expression is evaluated. If the qualifying expression evaluates
to null , a NullPointerException is raised, and the class instance creation expression completes
abruptly. If the qualifying expression completes abruptly, the class instance creation ex-
pression completes abruptly for the same reason.
Next, space is allocated for the new class instance. If there is insufficient space to allocate
the object, evaluation of the class instance creation expression completes abruptly by
throwing an OutOfMemoryError .
The new object contains new instances of all the fields declared in the specified class type
and all its superclasses. As each new field instance is created, it is initialized to its default
value (§ 4.12.5 ) .
Next, the actual arguments to the constructor are evaluated, left-to-right. If any of the argu-
ment evaluations completes abruptly, any argument expressions to its right are not evalu-
ated, and the class instance creation expression completes abruptly for the same reason.
Next, the selected constructor of the specified class type is invoked. This results in invoking
at least one constructor for each superclass of the class type. This process can be directed
by explicit constructor invocation statements (§ 8.8 ) and is described in detail in § 12.5 .
The value of a class instance creation expression is a reference to the newly created object
of the specified class. Every time the expression is evaluated, a fresh object is created.
Search WWH ::




Custom Search