What are functional interfaces used for in Java 8?
What are functional interfaces used for in Java 8?
400
17-Aug-2023
Aryan Kumar
18-Aug-2023Functional interfaces are used in Java 8 for a variety of purposes, including:
Here are some examples of how functional interfaces are used in Java 8:
Runnableinterface is a functional interface that declares a single abstract method,run(). Therun()method is executed when theRunnableobject is executed.Comparatorinterface is a functional interface that declares two abstract methods,compare()andequals(). Thecompare()method compares two objects and returns an integer indicating their relative order. Theequals()method compares two objects and returns a boolean value indicating whether the objects are equal.Predicateinterface is a functional interface that declares a single abstract method,test(). Thetest()method takes an object as its input and returns a boolean value indicating whether the object satisfies the predicate.