In my previous blog, I explained the concept of a functional interface introduced in Java 8. To recapitulate, a functional interface is an interface that has a single abstract method that can be defined with the help of a simple lambda expression, thus giving Java a functional aspect.

Along with introducing this new concept, Java has also provided us with a set of 43 predefined functional interfaces. Now to get a hang of how to use these predefined functional interfaces, understanding only a handful of them is enough. These functional interfaces are present in the java.util.function package, which was added with the Java 8 release. If you are looking for the documentation of these interfaces, or if you’re looking for the definition of a particular interface, you can always check out the official page for this package.

In this blog, I intend to cover a few important and fundamental predefined functional interfaces that are ubiquitous in the Java 8 world, such as:

  • Consumer
  • Supplier
  • Predicate
  • Function

Before we start exploring the above listed interfaces, let’s ask ourselves a simple question, **why do we need these predefined functional interfaces in the first place? **In the previous blog, we designed the interface Calculator and we looked at various ways of defining the calculate method via lambda expressions. We didn’t need any of these predefined interfaces because it was a small and simple use case, i.e. to define a calculate method.

#functional-programming #object-oriented #java8 #lambda #java

Predefined Functional Interfaces — Java 8
1.20 GEEK