A lambda snapshots the value of a captured local variable when it is created; because the variable must be effectively final, that snapshot can never go stale even if the lambda is called much later.
int base = 100;
Supplier<Integer> supplier = () -> base + 1;
System.out.println("First call: " + supplier.get());
System.out.println("base is still: " + base);
System.out.println("Second call, same result: " + supplier.get());
First call: 101
base is still: 100
Second call, same result: 101
Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.
Published 2026-09-27