Java Reference
In-Depth Information
Figure 9.1. Adding a method to an interface
In a nutshell, adding a method to an interface is the source of many problems; existing classes
implementing the interface need to be changed to provide an implementation for the method. If
you're in control of the interface and all the implementations, then it's not too bad. But this is
often not the case. This is the motivation for default methods: they let classes automatically
inherit a default implementation from an interface.
So if you're a library designer, this chapter is important because default methods provide a
means to evolve interfaces without causing modifications to existing implementations. Also, as
we explain later in the chapter, default methods can help structure your programs by providing
a flexible mechanism for multiple inheritance of behavior: a class can inherit default methods
from several interfaces. Therefore, you may still be interested in finding out about default
methods even if you're not a library designer.
 
Search WWH ::




Custom Search