Supplier Functional Interface

81 Views Asked by At

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?

1

There are 1 best solutions below

0
Chandika On BEST ANSWER

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.