0 votes
in JAVA by
Name some of the functional interfaces in the standard library

1 Answer

0 votes
by

In Java 8, there are a lot of functional interfaces are introduced in the java.util.function package and the more common ones include but are not limited to:

Function – it takes one argument and returns a result

Consumer – it takes one argument and returns no result (represents a side effect)

Supplier – it takes no argument and returns a result

Predicate – it takes one argument and returns a boolean

BiFunction – it takes two arguments and returns a result

BiConsumer - it takes two (reference type) input arguments and returns no result

BinaryOperator – it is similar to a BiFunction, taking two arguments and returning a result. The two arguments and the result are all of the same types

UnaryOperator – it is similar to a Function, taking a single argument and returning a result of the same type

Runnable: use to execute the instances of a class over another thread with no arguments and no return value.

Callable: use to execute the instances of a class over another thread with no arguments and it either returns a value or throws an exception.

Comparator: use to sort different objects in a user-defined order

Comparable: use to sort objects in the natural sort order

...