Standard functional interfaces
Most of the interfaces provided in the java.util.function
package are specializations of the following four interfaces: Consumer<T>
, Predicate<T>
, Supplier<T>
, and Function<T,R>
. Let’s review them and then look at a short overview of the other 39 standard functional interfaces.
Consumer<T>
By looking at the Consumer<T>
interface definition, <indexentry content="standard functional interfaces:Consumer">
, you can already guess that this interface has an abstract method that accepts a parameter of type T
and does not return anything. Well, when only one type is listed, it may define the type of the return value, as in the case of the Supplier<T>
interface. But the interface name serves as a clue: the consumer
name indicates that the method of this interface just takes the value and returns nothing, while supplier
returns the value. This clue is not precise but helps to jog the memory...