Java Reference
In-Depth Information
An anonymous class is never abstract 8.1.1.1 ) .
An anonymous class is always implicitly final 8.1.1.2 ).
An anonymous class is always an inner class (§ 8.1.3 ) ; it is never static 8.1.1 , § 8.5.1 ).
15.9.5.1. Anonymous Constructors
An anonymous class cannot have an explicitly declared constructor. Instead, a Java com-
piler must automatically provide an anonymous constructor for the anonymous class. The
form of the anonymous constructor of an anonymous class C with direct superclass S is as
follows:
• If S is not an inner class, or if S is a local class that occurs in a static context, then
the anonymous constructor has one formal parameter for each actual argument to
the class instance creation expression in which C is declared.
The actual arguments to the class instance creation expression are used to determ-
ine a constructor cs of S , using the same rules as for method invocations (§ 15.12 ) .
The type of each formal parameter of the anonymous constructor must be identical
to the corresponding formal parameter of cs .
The body of the constructor consists of an explicit constructor invocation
8.8.7.1 ) of the form super(...) , where the actual arguments are the formal paramet-
ers of the constructor, in the order they were declared.
• Otherwise, the first formal parameter of the constructor of C represents the value
of the immediately enclosing instance of i with respect to S . The type of this para-
meter is the class type that immediately encloses the declaration of S .
The constructor has an additional formal parameter for each actual argument to the
class instance creation expression that declared the anonymous class. The n 'th
formal parameter e corresponds to the n-1 'th actual argument.
The actual arguments to the class instance creation expression are used to determ-
ine a constructor cs of S , using the same rules as for method invocations (§ 15.12 ) .
The type of each formal parameter of the anonymous constructor must be identical
to the corresponding formal parameter of cs .
The body of the constructor consists of an explicit constructor invocation
8.8.7.1 ) of the form o.super(...) , where o is the first formal parameter of the con-
structor, and the actual arguments are the subsequent formal parameters of the con-
structor, in the order they were declared.
Search WWH ::




Custom Search