Which BiPredicate Lambda Declaration Using var Is Valid?
Short answer
B With BiPredicate, lambda parameters declared with var must all use var in parentheses, so (var x, var y) is the only valid form.
Question
Key Takeaways
The exam tests whether you know that var in a lambda parameter list is all-or-nothing and still requires parentheses, and the trap is picking a declaration that illegally mixes var with an explicit type like Integer or with an implicitly typed parameter.
This 1Z0-819 item tests the Java lambda parameter syntax rules for var: a lambda that declares any parameter with var must use var on every parameter and keep the parentheses. Of the four BiPredicate declarations shown, only (var x, var y) -> (x.equals(y)) satisfies JLS 15.27.1 and compiles.
Common mistake: Option A is the most attractive wrong answer because mixing var x with an explicit Integer y looks flexible and still reads naturally, but JLS 15.27.1 forbids mixing var with declared parameter types in the same lambda, so A does not compile.
Expert Analysis
Why the Answer Is Correct
B is valid because both lambda parameters are declared with var inside the mandatory parentheses: BiPredicate testEquality = (var x, var y) -> (x.equals(y));. JLS 15.27.1 states that if one lambda parameter is declared with var, then all parameters must be declared with var, and the parameter list must remain parenthesized. Here the target type is the raw BiPredicate, so the function type is erased and the inferred parameter types are Object, which makes x.equals(y) a legal invocation. No rules on mixing, missing parentheses, or inferred types are violated, so B compiles cleanly.
Why the Other Options Are Wrong
A mixes var x with the explicit type Integer y in the same parameter list, which JLS 15.27.1 explicitly forbids — you must either use var everywhere or explicit types everywhere. C drops the parentheses (var x, var y ->...), and an implicitly typed or var-typed lambda parameter list must always be enclosed in parentheses, so this is a syntax error. D mixes var x with the implicitly typed parameter y, which is the same all-or-nothing violation as A but in the opposite direction: once var appears, every parameter needs var. None of A, C, or D can be compiled, while B is the only declaration that satisfies every lambda parameter rule.
Community Comment Notes
ASPushkin reasoned through the same rule set, stating that in A "there is no mix var with the explicit types", that B is fine, and that C is a "syntax error without brackets". Another learner noted that D is a compound form that is not allowed, which matches the all-or-nothing var requirement. d7bb0b2 also chose B, adding that because the BiPredicate variable is declared without type arguments, the parameters resolve to Object rather than a specific type. A third commenter simply cross-referenced this item as similar to numbered questions 22 and 204 seen previously, suggesting the var-lambda rule recurs on the exam.
Official Reference
- https://docs.oracle.com/javase/specs/jls/se11/html/jls-15.html#jls-15.27.1
- https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/function/BiPredicate.html
These links open the official vendor documentation in a new tab.
Exam Strategy
Memorize the one-line rule — in a lambda, var is all-or-nothing and the parameter list must stay in parentheses — then scan each option for a single mixed or unparenthesized parameter. On 1Z0-819, syntax-validity questions are answered by compiling mentally, not by judging which style looks nicer.
Frequently Asked Questions
Why can't var x be mixed with an explicit Integer y in the same BiPredicate lambda?
Does a lambda whose parameters are all declared with var still need parentheses?
Community Votes
100% of anonymous learners picked answer B. Votes are pick records left by other test-takers — they are not the verified answer.
Discussion 3 contributions
Compiled from public community threads and reader submissions, lightly edited for clarity. Handles and vote tallies are shown as recorded, and comments reflect the views of individual contributors.
From public community threads 3
-
ASPushkin 👍 1 Answered BA) there is no mix var with the explicit types B) ok C) syntax error without brackets D) compound not allowed
-
d7bb0b2 👍 1B: Bcos Bipredicated is declared without type and then cannot pass other Type that Object
-
ASPushkin 👍 1similar to 22, 204
Reader comments & corrections
No reader corrections yet — spotted an error or have a note? Share it below.