Default methods and functions

Default methods can be added to interfaces. They permit existing interfaces to be expanded to include new methods without breaking the older code. It is the default method of an interface that has an implementation. For example, consider a class that implements an interface, and then later a default method is added to the interface. The class has to implement all of the interfaces' abstract methods or the class will be abstract. However, since a default method is not abstract and has an implementation, it does not affect the class.

The addition of functions to Java suggests the need to incorporate their use with older classes and interfaces. After all, it is desirable to take advantage of existing code when possible ...

Get Learning Java Functional Programming 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.