Section 7.1: The Supplier Interface
Supplier is a functional interface that is used to generate data. A Supplier object is specified with type parameter T. Its functional method, called get, takes no arguments and returns an object of type T.
@FunctionalInterface
public interface Supplier<T>
{
T get();
}
A supplier that generates a random integer is defined as follows:
Supplier<Integer> generateInteger = () ->
{
Random rand = new Random();
return rand.nextInt(100);
};
A supplier that generates a string using a Scanner object is defined as follows:
Supplier<String> generateString = () ->
{