CodeX
Published in

CodeX

A couple of use cases for anonymous classes in Java

Photo by DANNY G on Unsplash

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,

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store