Java Reference
In-Depth Information
Inner classes implementing a single-method interface can be written in a much more concise
fashion as lambda expressions (see Chapter 9 ) .
Providing Callbacks via Interfaces
Problem
You want to provide callbacks—that is, have unrelated classes call back into your code.
Solution
One way is to use a Java interface.
Discussion
An interface is a class-like entity that can contain only abstract methods and final fields. As
we've seen, interfaces are used a lot in Java! In the standard API, the following are a few of
the commonly used interfaces:
Runnable , Comparable , and Cloneable (in java.lang )
List , Set , Map , and Enumeration/Iterator (in the Collections API; see Chapter 7 )
ActionListener , WindowListener , and others (in the GUI layer; see Action Handling:
Making Buttons Work )
Driver , Connection , Statement , and ResultSet (in JDBC; see JDBC Setup and Con-
nection )
▪ The “remote interface”—the contact between the client and the server—is specified as an
Interface (in RMI, CORBA, and EJB)
Search WWH ::




Custom Search