Section 10.10 Java SE 8 Interface Enhancements

• In Java SE 8, an interface may declare default methods—that is, public methods with concrete implementations that specify how an operation should be performed.

• When a class implements an interface, the class receives the interface’s default concrete implementations if it does not override them.

• To declare a default method in an interface, you simply place the keyword default before the method’s return type and provide a complete method body.

• When you enhance an existing an interface with default methods—any classes that implemented the original interface will not break—it’ll simply receive the default method implementations.

• With default methods, you can declare common method implementations ...

Get Java™ How To Program (Early Objects), Tenth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.