Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / Java

util.function.Supplier: practical reference

util.function.Supplier: practical reference: Supplier<T> is a zero-argument functional interface whose get method supplies a result of type T.

Version: Java SE 21 (JLS and Java SE API); examples verified on the repository Java runtime

Syntax

java.util.function.Supplier

Supplier is a zero-argument functional interface whose get method supplies a result of type T.

Use it for lazy value creation, factories, default configuration, and stream element generation.

The contract does not require a new or distinct result on each get, nor does it promise purity, caching, or thread safety.

get may legally return the same object or null when the application permits it; the interface declares no checked exceptions.

The example exercises the documented element in a small deterministic program and compares exact standard output.

Examples

public class Main {
    public static void main(String[] args) throws Exception {
        java.util.function.Supplier<String> value = () -> "Java";
        System.out.println(value.get());
    }
}

Result

Java

The example exercises the documented element in a small deterministic program and compares exact standard output.

Sources