15.8
Class Instance Creation Expressions
EXPRESSIONS
15.8 Class Instance Creation Expressions
A class instance creation expression is used to create new objects that are
instances of classes.
ClassInstanceCreationExpression:
new
ClassType
(
ArgumentList
opt
)
ArgumentList:
Expression
ArgumentList
,
Expression
In a class instance creation expression, the
ClassType
must name a class that
is not
abstract
. This class type is the type of the creation expression.
The arguments in the argument list, if any, are used to select a constructor
declared in the body of the named class type, using the same matching rules as for
method invocations ( 15.11). As in method invocations, a compile time method
matching error results if there is no unique constructor that is both applicable to
the provided arguments and the most specific of all the applicable constructors.
15.8.1 Run time Evaluation of Class Instance Creation Expressions
At run time, evaluation of a class instance creation expression is as follows.
First, space is allocated for the new class instance. If there is insufficient space
to allocate the object, evaluation of the class instance creation expression com
pletes abruptly by throwing an
OutOfMemoryError
( 15.8.2).
The new object contains new instances of all the fields declared in the speci
fied class type and all its superclasses. As each new field instance is created, it is
initialized to its standard default value ( 4.5.4).
Next, the argument list is evaluated, left to right. If any of the argument eval
uations 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.6)
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.
314
footer
Our partners:
PHP: Hypertext Preprocessor Best Web Hosting
Java Web Hosting
Inexpensive Web Hosting
Jsp Web Hosting
Cheapest Web Hosting
Jsp Hosting
Cheap Hosting
Visionwebhosting.net Business web hosting division of Web
Design Plus. All rights reserved