Functional Interface

Functional interface as concept is not new to java 8! It was there with earlier java version as well.

Any interface with only single abstract method is called Functional Interface. Yes!

We already have such functional interface available like Runnable, Comparator , Callable and few others. All these interfaces have exactly one abstract method, hence they all are functional interface.

Now, in JAVA 8, functional interface is enhanced and made it more powerful along with Lambda expression.
In short, Lambda expression is   (param list ) - > method body

There are new functional interfaces have been introduced in java 8.

java.util.function  a new package introduced in java 8.
This package has multiple functional interfaces for various scenario usage.

functional interface can provide target type in multiple context, such as assignment context, method invocation and cast context.

stream.filter(e -> e.getSize(0) > 10 );  // method invocation

Predicate<String> pre = String::isEmpty; // assignment context

stream.map((ToIntFunction) e -> e.getSize())   // cast context

No comments: