Table of contents
- Introduction to Supplier functional interface
- When to use
- Some specializations of Suppliers interface
- Wrapping up
Introduction to Supplier functional interface
Supplier is a functional interface that is used to generate data.
Below is its definition on Java docs.
@FunctionalInterface
public interface Supplier<T> {
T get();
}
For example:
Supplier<Integer> intRand = () -> {
Random rand = new Random();
return rand.nextInt(140);
};
When to use
- When our methods or functions do not need input, but it expected output.
Some specializations of Suppliers interface
Belows are some specializations of Supplier:
@FunctionalInterface
public interface BooleanSupplier<T> {
boolean getAsBoolean();
}
@FunctionalInterface
public interface IntSupplier<T> {
int getAsInt();
}
@FunctionalInterface
public interface LongSupplier<T> {
long getAsLong();
}
@FunctionalInterface
public interface DoubleSupplier<T> {
double getAsDouble();
}
Wrapping up
Refer: