intermediateJava 8 & Streams27 of 436
Predicate, Function, Consumer, Supplier — explain and differentiate
Tests whether you can place each by its signature shape -- Predicate<T> takes a value and returns boolean, Function<T,R> takes a value and returns a different type, Consumer<T> takes a value and returns nothing, Supplier<T> takes nothing and returns a value -- the four shapes that cover almost every functional-interface use case in the JDK.
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