O'Reilly logo

Java Garage by Eben Hewitt

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 20. Blog: Inner Classes and Event Handlers

Beware when using inner classes, anonymous inner classes in particular. They are the subjects of much debate within the Java community. Developers who don't like their use say they break encapsulation—one of the key principles of object-oriented programming—and that they're hard to read and difficult for beginners to understand.

Developers who promote their use during late night local television shows point to their convenience and elegance. You need to know about them to read and write Swing application code. But in general, you don't need them, and your code is probably clearer and more flexible without them.

My rule is this: Use anonymous inner classes to handle actions and events. Don't ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required