As we know Consumer<T>
functional interface is used in forEach()
so similarly does Java has a use case for Supplier
other than the custom ones?
Asked
Active
Viewed 65 times
-1

Slaw
- 37,820
- 8
- 53
- 80

Mrinal Gupta
- 11
- 4
-
Here is every use of `java.util.function.Supplier` in the standard library for Java 19: https://docs.oracle.com/en/java/javase/19/docs/api/java.base/java/util/function/class-use/Supplier.html – Slaw Feb 06 '23 at 02:11
-
And for fun, here's the same for `java.util.function.Consumer`: https://docs.oracle.com/en/java/javase/19/docs/api/java.base/java/util/function/class-use/Consumer.html – Slaw Feb 06 '23 at 02:12
1 Answers
0
java.util.Optional.orElseGet(Supplier<T> supplier)
can be used to provide a default value for an Optional if it is empty.
java.util.stream.Stream.generate(Supplier<T> s)
can be used to generate a stream of values.

Chandika
- 93
- 1
- 8