beginnerFunctional Programming
What is the Supplier functional interface in Java, and when do you use it?
Supplier<T> takes no arguments and returns a value of type T, via its abstract method T get(). It's used for lazy or deferred value generation — e.g. Optional.orElseGet(supplier), where the supplier is only invoked if the Optional is actually empty, avoiding unnecessary work compared to orElse(), which always evaluates its argument eagerly.
Ready to master this question?
Generate a complete walkthrough — background, the full answer in plain language, a working code example explained line by line, a real-world scenario, common mistakes, and how this same question gets asked in different ways.
Sign in to generate a response