What is a Supplier?
Supplier is a predefined functional interface like Consumer, present in java.util.function package. It has one abstract method called get();
Supplier can be used to supply some value based on some operation, Supplier won't take any input and it will always supply objects.
Supplier can be used to supply some value based on some operation, Supplier won't take any input and it will always supply objects.
1 | interface Supplier<R> { |
Supplier example 1:
1 | package com.blogspot.ekumeedkiasha; |
Property | Predicate | Function | Consumer | Supplier |
What | To take some Input and perform some conditional checks | To take some Input and perform required Operation and return the result | To consume some Input and perform required Operation. It won’t return anything. | To supply some Value base on our Requirement |
Abstract method name | public boolean test (T t); | public R apply (T t); | public void accept (T t); | public R get(); |
Default Methods | and(), or(), negate() | andThen(), compose() | andThen() | N/A |
Static Method | isEqual() | identify() | N/A | N/A |
EmoticonEmoticon