Java Reference
In-Depth Information
15.9.1. Determining the Class being Instantiated
If the class instance creation expression ends in a class body, then the class being instantiated
is an anonymous class. Then:
• If the class instance creation expression is an unqualified class instance creation ex-
pression, then TypeDeclSpecifier TypeArgumentsOrDiamond opt must denote a type,
T 4.3 , § 4.5 ) , or a compile-time error occurs.
It is a compile-time error if the class or interface named by T is not accessible (§ 6.6 )
or if T is an enum type (§ 8.9 ).
If T denotes a class, then an anonymous direct subclass of the class named by T is
declared. It is a compile-time error if the class denoted by T is a final class.
If T denotes an interface, then an anonymous direct subclass of Object that imple-
ments the interface named by T is declared.
In either case, the body of the subclass is the ClassBody given in the class instance
creation expression.
The class being instantiated is the anonymous subclass.
• Otherwise, the class instance creation expression is a qualified class instance cre-
ation expression.
It is a compile-time error if the Identifier after the new token is not the simple name
6.2 ) of an accessible (§ 6.6 ) non- final inner class (§ 8.1.3 ) that is a member of the
compile-time type of the Primary .
It is a compile-time error if the name is ambiguous (§ 8.5 ) or denotes an enum type.
When TypeArguments are provided after the name, it is a compile-time error if the
type arguments, when applied to the named class, do not denote a well-formed para-
meterized type (§ 4.5 ) .
Let T be the type named by the Identifier and any type arguments. An anonymous
direct subclass of the class named by T is declared. The body of the subclass is the
ClassBody given in the class instance creation expression.
The class being instantiated is the anonymous subclass.
If a class instance creation expression does not declare an anonymous class, then:
• If the class instance creation expression is an unqualified class instance creation ex-
pression, then the TypeDeclSpecifier must denote a class that is accessible (§ 6.6 )
and is not an enum type and not abstract , or a compile-time error occurs.
Search WWH ::




Custom Search