Can be particularly useful when...
An anonymous class can be particularly useful in those cases where
- No reason for object of the anonymous class to exist in the absence of
an object of the enclosing class.
- No reason for an object of the anonymous class to exist outside a method
of the enclosing class.
- Methods of the object of the anonymous class need access to members of
the object of the enclosing class.
- Methods of the object of the anonymous class need access to final
local variables and method parameters belonging to the method in which the
anonymous class is defined.
- Only one instance of the anonymous class is needed.
- No need for the class to have a name that is accessible elsewhere in the
program.