A couple of use cases for anonymous classes in Java
When I first learned about anonymous classes in Java, I didn’t quite see the point. I understood the syntax well enough to recognize anonymous classes in applications of Java’s Abstract Window Toolkit (AWT).
Those didn’t quite seem to make sense to me. You want a particular window to close when a user clicks the Close button? Subclass WindowAdapter
anonymously. For example,