J.VII · Java 25 practice question

According to JEP 441, what does extending pattern matching to `switch` allow a Java program to do?

Choose one answer
Check answer and explanation

Correct answer: Test an expression against multiple patterns, each with a specific action, to express data-oriented queries concisely and safely.

Explanation

JEP 441 extends pattern matching to `switch` expressions and statements so an expression can be tested against multiple patterns, each with a specific action, making complex data-oriented queries concise and safe.

Common trap

Pattern matching for `switch` does not introduce compile-time macros or allow mutating fields directly inside `case` labels.

Source: JEP 441: Pattern Matching for switch — Summary
Checked against the cited text on 2026-11-27.

Report an error in this question