In Java a functional interface is one that allows the passing of code as data, and contains (among other things, perhaps, including other methods) a single abstract method. The implementation of such an abstract method is often passed to an algorithm to specify or modify that algorithm's behavior (for example, a sort algorithm that wants to sort in several different ways). Prior to Java 8 this was accomplished by creating a new (possibly anonymous) class that implemented the interface and passing an object of this class to the algorithm in question. With Java 8 this can be achieved more easily by using a lambda function or method reference.
A method reference, in turn, can be any of the following:
In what follows, when we refer to a total ordering on a collection of objects just think of being able to compare any two objects from that collection to see if they are the same, or, if not, which "comes first".
In the following list of interfaces, Comparable<T> and Supplier<T> contain one method each (the one shown) but each of the other interfaces contains more than one. When implementing any of these interfaces, the only method you absolutely must implement is the first one shown below, since all the other methods are either default or static. One or more of the other methods may of course be useful in your situation, and you may even want or need to override one of those other methods.
java.lang.Comparable<T>compareTo()
method is referred to as its "natural" comparison method.int compareTo(T o) [Compares this object with the
specified object for order.]
T).int compare(T o1, T o2) [Compares its two arguments for
order.]
boolean test(T t) [Evaluates this predicate on the given
argument.]default Predicate<T> and() [Returns a predicate that
represents this predicate combined with another predicate that is the
argument of and().]default Predicate<T> or() [Returns a predicate that
represents this predicate combined with another predicate that is the
argument of or().]default Predicate<T> negate() [Returns a predicate
that represents the logical negation of this predicate.]static <T> Predicate<T> isEqual(Object
targetRef) [Returns a predicate that tests if two arguments are
equal according to Object.equals(Object, Object).]
T get() [Does not have to return a new or distinct
result on each call.]
void accept(T t) [Performs this operation on the given
argument.]default Consumer<T> andThen(Consumer<? super T>
after) Returns a composed Consumer that performs,
in sequence, this operation followed by the after operation.
R apply(T t) [Applies this function to the given
argument.]