Wednesday, July 15, 2015

Java Lambda - Supplier Functional Interface

Supplier Functional Interface

Supplier is an interface that represents the supplier of results. Supplier interface can take argument of any type.

For Supplier interface there is no requirement that a new or distinct result must be returned each time supplier is invoked.


Supplier Interface Declaration
public interface Supplier<T>
Supplier is generic version interface that returns the result of given type.


get() method
T get();

get() method returns the result. Let us take simple example to return the String.
Supplier<String> result = () -> "Returned String";
System.out.println(result.get()); //Outputs Returned String


That’s all on Supplier Interface.

Read about important java.util.function package’s interface here. Consumer, Function, Supplier, BinaryOperator & Predicate Functional Interfaces. I have also written on High Order functions using Function functional interface.



No comments:

Post a Comment

Ads Inside Post