Chapter 3. Functional Interfaces of the JDK
Many functional programming languages use only a singular and dynamic concept of “functions” to describe their lambdas, regardless of their arguments, return type, or actual use case.
Java, on the other hand, is a strictly typed language requiring tangible types for everything, including lambdas.
That’s why the JDK provides you with over 40 readily available functional interfaces in its java.util.function package to kick-start your functional toolset.
This chapter will show you the most important functional interfaces, explain why there are so many variations, and show how you can extend your own code to be more functional.
The Big Four Functional Interface Categories
The 40+ functional interfaces in java.util.function fall into four main categories, with each category representing an essential functional use case:
-
Functions accept arguments and return a result.
-
Consumers only accept arguments but do not return a result.
-
Suppliers do not accept arguments and only return a result.
-
Predicates accept arguments to test against an expression and return a
booleanprimitive as their result.
These four categories cover many use cases, and their names relate to functional interface types and their variants.
Let’s take a look at the four main categories of functional interfaces.
Functions
Functions, with their corresponding java.util.function.Function<T, R> interface, are one of the most central functional interfaces. They represent ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access