Java SE 11 Developer (1Z0-819) — Question 179
Which two are valid statements? (Choose two.)
Answer options
- A. BiPredicate test = (Integer x, final var y) -> (x.equals(y));
- B. BiPredicate test = (Integer x, final Integer y) -> (x.equals(y))
- C. BiPredicate test = (var x, final var y) -> (x.equals(y));
- D. BiPredicate test = (final Integer x, var y) -> (x.equals(y));
- E. BiPredicate test = (final var x, y) -> (x.equals(y));
Correct answer: B, C
Explanation
Option B is correct because it uses explicit types for both parameters, which is valid. Option C is also correct as it uses 'var' for both parameters while maintaining compatibility with the BiPredicate functional interface. The other options either mix types incorrectly or violate the rules for using 'var'.