Java Reference
In-Depth Information
(
ArgumentList
opt
)
ClassBody
opt
Primary
. new
TypeArguments
opt
Identifier TypeArgumentsOrDiamond
opt
(
ArgumentList
opt
)
ClassBody
opt
TypeArgumentsOrDiamond:
TypeArguments
<>
ArgumentList:
Expression
ArgumentList
,
Expression
A class instance creation expression specifies a class to be instantiated, possibly followed
If the type argument list to the class is empty — the diamond form “
<>
” — the type argu-
ments of the class are inferred. It is legal, though strongly discouraged as a matter of style,
to have white space between the “
<
” and “
>
” of a diamond.
either be inferred or passed explicitly. If passed explicitly, the type arguments to the con-
structor immediately follow the keyword
new
.
It is a compile-time error if a class instance creation expression provides a constructor type
argument list but uses “
<>
” in place of a class type argument list.
This rule is introduced because inference of a generic class's type arguments may in-
fluence the constraints on a generic constructor's type arguments.
It is a compile-time error if any of the type arguments used in a class instance creation ex-
The exception types that a class instance creation expression can throw are specified in
Class instance creation expressions have two forms:
•
Unqualified class instance creation expressions
begin with the keyword
new
.
An unqualified class instance creation expression may be used to create an in-
•
Qualified class instance creation expressions
begin with a
Primary
.