- Showing "tight" relationships between two classes by defining one within another.
- Keeping 'trivial' objects separate from 'important' ones by keeping them nameless. Anonymous inner classes are frequently used to describe an object that is detailed enough to be separated from a "higher-level" class but dependent enough on the surrounding code that it is best left nameless.
- Providing a style of code-writing that seems cumbersome or harder to maintain with normal package scoping.
Originally posted by David Crossett:
I don't like having to write an entire separate class just to have a frame exit or something simple like that. Again, I am not a professional and there may be dis-advantages to this style (please let me know if this is so!!), but I sure like it for now.
Anonymous inner classing can be a real drag to read, maintain and debug. That's the big drawback. It also opens the door to a few perverse, if amusing, code styles that I won't go into. Don't want to scare the young 'uns.