Supplier : Supplier is a functional Interface is coming form java.util.funcation package. Which has been introduces in java 8 to implement functional programming in java.
interface Supplier<T>{
public T get();
}
Note: T is type of results Supplied by the Supplier.
- Supplier does not take any argument but produces a value of type T.
- Supplier functional Interface contains only one default method is call get().
- get() method is abstract method so under supplier interface.
- Supplier functional interface don't contain any static and default method.
Example 1: How to get System date using Supplier functional interface.
Output: Mon Nov 04 14:52:32 IST 2019
Example 2: How to generate random name using supplier functional interface.
Output:-
Baby
Pinny
Maya
Example 3: How to generate random 6-digit OTP using Supplier Functional Interface.
Output:
515121
550490
650770
609529
Example 4 : How to get random password using Supplier functional interface.
Output:-
A9A2A5A0
A9A8A2A2
A0A5A2A2
A3A7A6A8
Comparison Table of Predicate, Function, Consumer and Supplier Functional Interface.
0 Comment to "Supplier Interface"
Post a Comment