Java SE 8 Interfaces Allow Inheritance of Method Implementations

Functional interfaces must contain only one abstract method, but may also contain default methods and static methods that are fully implemented in the interface declarations. For example, the Function interface—which is used extensively in functional programming—has methods apply (abstract), compose (default), andThen (default) and identity (static).

When a class implements an interface with default methods and does not override them, the class inherits the default methods’ implementations. An interface’s designer can now evolve an interface by adding new default and static methods without breaking existing code that implements the interface. For example, interface Comparator

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.