Java SE 11 Developer (1Z0-819) — Question 190
Which is a valid statement?
Answer options
- A. BiPredicate testEquality = (var x, Integer y) -> (x.equals(y));
- B. BiPredicate testEquality = (var x, var y) -> (x.equals(y));
- C. BiPredicate testEquality = var x, var y -> (x.equals(y));
- D. BiPredicate testEquality = (var x, y) -> (x.equals(y));
Correct answer: B
Explanation
Option B is correct because it uses the proper syntax for a BiPredicate, allowing both parameters to be of the 'var' type. Option A restricts the second parameter to an Integer, which is not generic. Option C has a syntax error with the missing parentheses, and Option D lacks type declaration for the second variable, making it invalid.