J.VII · Java 25 practice question
According to the Java Language Specification, how is pattern matching classified relative to statement execution and expression evaluation?
Check answer and explanation
Correct answer: It is a distinct run-time process of testing a value against a pattern and initializing any declared pattern variables on a match
Explanation
Pattern matching is a distinct run-time process of testing a value against a pattern and initializing any declared pattern variables on a match, separate from statement execution and expression evaluation.
Common trap
While instanceof is a boolean expression that uses pattern matching, pattern matching itself is defined as distinct from expression evaluation. It is also a run-time process rather than a compile-time macro expansion.
Source: JLS SE 25 §14.30.2. Pattern Matching
Checked against the cited text on 2026-11-25.