Lambda Expressions Flashcards
7 cards from real 1Z0-819 practice questions. Tap to flip, then mark Knew It or Still Learning — missed cards come back until you master them.
Read the first 7 Lambda Expressions flashcards as text
Which of the following lambda expressions is equivalent to the method reference Integer::parseInt?
Answer: s -> Integer.parseInt(s)
Integer::parseInt is a static method reference equivalent to the lambda s -> Integer.parseInt(s).
A lambda that takes no arguments and returns void corresponds to which functional interface?
Answer: Runnable
Runnable's run() method takes no parameters and returns void, making it the natural fit for () -> { ... } style lambdas.
What does Function.identity() return?
Answer: A function that returns its input argument unchanged
Function.identity() returns a Function that always returns its input argument (t -> t).
Given: Predicate isEven = n -> n % 2 == 0; Predicate isPositive = n -> n > 0; which call correctly creates a predicate for even AND positive numbers?
Answer: isEven.and(isPositive)
Predicate.and() returns a composed predicate that represents a short-circuit logical AND of both predicates.
Which of the following is TRUE about serializing lambda expressions in Java?
Answer: Lambdas are serializable only if the target functional interface extends Serializable.
A lambda is serializable if and only if its target type (the functional interface) extends java.io.Serializable.
What is the output of: List.of("a","bb","ccc").stream().filter(s -> s.length() > 1).count();
Answer: 2
filter keeps "bb" and "ccc" (lengths 2 and 3, both > 1), so count() returns 2.
When using a lambda to implement an interface with a throws clause on the abstract method, what must the lambda body do?
Answer: Handle or propagate only checked exceptions declared by the functional interface method
The lambda body can throw checked exceptions only if the functional interface's abstract method declares them; otherwise only unchecked exceptions are permitted.