3 ms·
In the case of &&, the left hand side of the expression (Tuner t) isn't a boolean expression. In the case of "if", you're right, the grammar doesn't work, both
by mason55 4y ago
In the case of &&, the left hand side of the expression (Tuner t) isn't a boolean expression.
In the case of "if", you're right, the grammar doesn't work, both because the syntax of Java already says that the if condition must be enclosed in parentheses and also because an if block is a statement and you need an expression here.
To make either of those work, you'd have to make the rest of the pattern matching syntax much worse.
- anyfoo 4y agoThe “&&” one is super confusing indeed, but the “if” one is just a question of style. It would be possible to reuse the “if” keyword for different grammar. python does it for its trinary operator, where there is an expression instead of a statement after “then” (e.g. “foo = if bar then 1 else 2”), but if Java does not have the same habit of reusing keywords already (not sure), it might not want to start now for consistency.