Functional Interfaces 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 Functional Interfaces flashcards as text
What is the correct return type of `BiFunction`?
Answer: Boolean
The third type parameter of BiFunction is the return type R, so Boolean is returned.
Given `Function f = String::length;` and `Function g = i -> "len:"+i;`, what does `f.andThen(g).apply("hi")` return?
Answer: "len:2"
andThen applies f first (length=2) then g, producing "len:2".
What is the difference between `Function.andThen(g)` and `Function.compose(g)`?
Answer: andThen applies g after this function; compose applies g before
andThen(g) means this → g; compose(g) means g → this, reversing the application order.
Which method on `Predicate` returns a new Predicate that is the logical negation of the original?
Answer: negate()
Predicate.negate() returns a new Predicate that represents the logical NOT of the original predicate.
What does `Predicate.and(Predicate other)` short-circuit on?
Answer: It short-circuits when the first predicate is false
Predicate.and() short-circuits on false — if the first predicate returns false, the second is never evaluated.
Which functional interface represents an operation that accepts two input arguments and returns no result?
Answer: BiConsumer
BiConsumer accepts two arguments and returns void, making it the two-argument form of Consumer.
What happens when you call `consumer1.andThen(consumer2).accept(x)`?
Answer: consumer1 is called first, then consumer2
Consumer.andThen() returns a composed Consumer that executes this consumer first, then the argument consumer.