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
by type arguments (§ 4.5.1 ) or a diamond (“ <> ”) if the class being instantiated is generic
8.1.2 ) , followed by (a possibly empty) list of actual value arguments to the constructor.
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.
If the constructor is generic (§ 8.8.4 ) , the type arguments to the constructor may similarly
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-
pression are wildcard type arguments (§ 4.5.1 ) .
The exception types that a class instance creation expression can throw are specified in
§ 11.2.1 .
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-
stance of a class, regardless of whether the class is a top level (§ 7.6 ) , member
8.5 , § 9.5 ) , local (§ 14.3 ) or anonymous class (§ 15.9.5 ) .
Qualified class instance creation expressions begin with a Primary .
Search WWH ::




Custom Search