Table of contents

Introduction to Supplier functional interface

Supplier is a functional interface that is used to generate data.

Below is its definition on Java docs.

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:

public interface BooleanSupplier<T> {
    boolean getAsBoolean();

public interface IntSupplier<T> {
    int getAsInt();

public interface LongSupplier<T> {
    long getAsLong();

public interface DoubleSupplier<T> {
    double getAsDouble();

Wrapping up


Functional Interfaces in Java ebook