Being lazy, I got this non-AWT example from the Nested Classes Specification
here:
Consider a method myEnumerate() which is responsible for returning an Enumeration of the elements in an array. (Look up Enumeration if you're not familiar with it.) This could be done using a
local class as follows:
This can also be done using an
anonymous class which does the exact same thing:
Study the differences in syntax carefully. Note that since an anonymous class has no name, it can only be used once, to create exactly one instance of itself. (How can you refer to it again since it has no name?) But if that's not a problem, it can be somewhat shorter to write than a local class.