Why a supplier instead of a manufacturer?
This is a very simple question, but someone here needs to know, so it's easy to get some points here.
In Java 8 in the package java.util.function
are four categories of functional interfaces: Consumer
, Supplier
, Function
and Predicate
. A Function
converts one input to one output. A Predicate
converts input to boolean
.
The signatures for single abstract methods in Consumer
and Supplier
are essentially opposite to each other:
For Consumer<T>
:
void accept(T t)
And for Supplier<T>
:
T get()
Since a Consumer
takes input and returns Supplier
nothing, but takes nothing and returns a value, they feel like opposites. If someone asked me what the opposite is Consumer
, my natural thought would be Producer
like the Producer-Consumer problem.
So my (admittedly stupid) question is: why not Supplier
called Producer
? Is there an obvious reason I am missing?
source to share
No one has answered this question yet
Check out similar questions: