Java Reference
In-Depth Information
Inner classes implementing a single-method interface can be written in a much more concise
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
)
▪ The “remote interface”—the contact between the client and the server—is specified as an
Interface
(in RMI, CORBA, and EJB)