JEP 427 proposes two notable changes to pattern matching in Java switch statements. First, guarded patterns (using &&) are replaced by when clauses, shifting ownership of case refinement from the pattern itself to the case construct. Second, null handling is clarified: without an explicit case null, switch will always throw a NullPointerException even if an unconditional pattern is present, preventing null from silently matching. However, this top-level null protection does not extend to nested patterns, creating an inconsistency. The author shares personal opinions on both changes, expressing skepticism about moving refinement out of the pattern syntax while approving of the stricter null behavior.
Sort: