Govt. Exams
Entrance Exams
Function<T, R> takes parameter T and returns R. Consumer<T> takes parameter T and returns void.
Runnable is the functional interface for operations with no parameters and no return value (void).
Without context, the parameter type cannot be inferred. The functional interface type determines the parameter type.
Ternary operator inside lambda requires braces and explicit return statement for type inference.
replaceAll() with a lambda expression modifies the list in-place, multiplying each element by 2. Result is [2, 4, 6].
Lambda expressions can only access local variables that are final or effectively final (not reassigned). This ensures thread-safety and consistency.
Constructor method references use ClassName::new syntax. String::new refers to the String constructor and can be used wherever a Supplier<String> is expected.
Without explicit type declarations or context, the compiler must infer types from usage. We can only determine they have a compareTo() method, likely Comparable types.
range(1, 4) generates 1, 2, 3. map(x -> x * x) produces 1, 4, 9. Printed without spaces gives '149'.
Since standard functional interfaces don't declare checked exceptions, you must either wrap in try-catch or create a custom functional interface that throws the checked exception.