The concept between Function
(Predicate
or Consumer
) is different over Supplier
.
A simple explanation table:
Function
transforms 1 input to 1 output. BiFunction
transforms 2 inputs. So theoretically, there can be TriFunction
etc...
Predicate
works same like Function
but the output is always boolean
.
Consumer
consumes 1 input and doesn't return anything (void
). BiConsumer
consumes 2 inputs. So theoretically, there can be TriConsumer
etc...
Now, Supplier
. The Supplier
turns nothing (0 inputs) into an output. Notice the functional interfaces above provide either one (Function
and Predicate
) or none (Consumer
) output.
Supplier
creates something from nothing and as you know, it's not possible to have more than one return type. Theoretically BiSupplier
would mean something like "Create something from two nothings" which in Java context makes no sense (however, "one nothing" does: Supplier<String> supplier = () -> "Hi";
).
You can understand Supplier<T>
as Function<Void, T>
(doesn't work in practice, but the principle is same). Now, BiSupplier<T>
would be BiFunction<Void, Void, T>
which really doesn't make any sense.