Java Reference
In-Depth Information
• If the class instance creation expression is an unqualified class instance creation
expression, then:
♦ If the class instance creation expression occurs in a static context, then a
compile-time error occurs.
♦ Otherwise, if
S
is a member of an enclosing class, then let
O
be the innermost
lexically enclosing class of which
S
is a member, and let
n
be an integer such
that
O
is the
n
'th lexically enclosing class of the class in which the class in-
stance creation expression appears.
The immediately enclosing instance of
i
with respect to
S
is the
n
'th lexically en-
closing instance of
this
.
♦ Otherwise, a compile-time error occurs.
• Otherwise, the class instance creation expression is a qualified class instance cre-
ation expression.
The immediately enclosing instance of
i
with respect to
S
is the object that is the
value of the
Primary
expression.
15.9.3. Choosing the Constructor and its Arguments
Let
C
be the class being instantiated. To create an instance of
C
,
i
, a constructor of
C
is
chosen at compile time by the following rules.
First, the actual arguments to the constructor invocation are determined:
• If
C
is an anonymous class, and the direct superclass of
C
,
S
, is an inner class,
then:
♦ If
S
is a local class and
S
occurs in a static context, then the arguments in the
argument list, if any, are the arguments to the constructor, in the order they ap-
pear in the expression.
♦ Otherwise, the immediately enclosing instance of
i
with respect to
S
is the first
argument to the constructor, followed by the arguments in the argument list of
the class instance creation expression, if any, in the order they appear in the
expression.
• Otherwise the arguments in the argument list, if any, are the arguments to the con-
structor, in the order they appear in the expression.
Second, a constructor of
C
and corresponding result type and
throws
clause are determined: