Home Segments Top Top Previous Next

692: Mainline

Many interfaces—such as the WindowListener interface—force you to define many methods that do nothing, as shown in Segment 685.

Accordingly, Java frequently provides adapter classes that serve as listener-interface companions. Such adapter classes implement all interface-required methods as do-nothing methods: Each such method has an empty body.

Thus, when you want to define a listener that implements only a small subset of the listener-interface methods, you define a subclass of the listener-implementing adapter. Then, you define shadowing methods in your subclass for whatever methods you want to perform real work.