Functional interfaces revisited
We used several functional interfaces in the previous examples. In this section, we will examine in more detail how they are created and illustrate a number of predefined functional interfaces available for immediate use in Java 8.
As mentioned earlier, a functional interface is an interface that has one and only one abstract method. It may have zero or more default methods. Since the interface has only one abstract method, the system is able to know which method to match to a lambda expression. This abstract method is called the functional method.
Creating a functional interface
The IntegerConcatenation
interface is duplicated here as an example. Note the use of the @FunctionalInterface
annotation. While not required, it will generate a syntax error if the interface is not a functional interface:
@FunctionalInterface public interface IntegerConcatenation { public String concatenate(Integer n1, Integer n2); }
Functional interfaces are easy to create. After...