Chapter 7

Using Inner Classes, Anonymous Classes, and Lambda Expressions

IN THIS CHAPTER

check Using inner classes

check Creating static inner classes

check Implementing anonymous classes

check Adding Lambda expressions

In this chapter, you find out how to use three advanced types of classes: inner classes, static inner classes, and anonymous inner classes. All three types are useful in certain circumstances. In particular, inner classes and anonymous inner classes are commonly used with graphical applications created with Swing. For more information about Swing, refer to Book 6. In this chapter, I concentrate on the mechanics of creating these types of classes.

You’ll also learn about a feature that was introduced with Java 8 called lambda expressions, which simplify the task of creating and using anonymous classes.

technicalstuff Once again, this chapter could have a Technical Stuff icon pasted next to every other paragraph. The immediate usefulness of some of the information I present in this chapter may seem questionable. ...

Get Java All-in-One For Dummies, 5th Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.