Govt Exams
Predicate<T> tests a condition and returns boolean. It's ideal for filtering. Function would return any type, Consumer doesn't return anything.
Function<T,R> takes one argument of type T and returns R. Here String -> Integer (length), so Function<String, Integer>.
Lambda must have parameter list (even if empty with ()). Missing parameter list '() -> x + y' is invalid syntax.
UnaryOperator square = x -> x * x;
System.out.println(square.apply(5));
UnaryOperator applies a function on its argument and returns result of same type. square.apply(5) returns 5*5 = 25.
The java.util.function package contains functional interfaces like Predicate, Consumer, Function, Supplier, and BiFunction introduced in Java 8.
A functional interface has exactly one abstract method. It can have multiple default methods. The @FunctionalInterface annotation can be used to mark it.
Valid Java lambda syntax uses arrow operator (->). Parameters can be typed or untyped, and the expression or block follows the arrow.
Lambda expressions provide a concise way to implement single abstract method (functional interfaces) without verbose anonymous class syntax.
Option A provides proper generic type safety without unnecessary constraints. While Option C adds a Serializable bound (sometimes desirable), Option A is the most flexible and commonly used pattern for generic response wrappers.
'? super T' allows writing T instances (contravariant), while '? extends T' allows safe reading (covariant). This combination enables flexible yet type-safe collection manipulation.