Type, record and primitive patterns, guards, sealed exhaustiveness, MatchException via separate compilation, and eight captured transcripts. Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TF9JWFvJSNm6HVzswzZU5a
865 B
865 B
patterns — Pattern matching from JDK 21 to 27
Companion code for the ankurm.com article Pattern Matching in Java: switch, Record Patterns and Primitive Patterns (JDK 21 to 27). The explanation lives in the article; this folder holds the runnable sources and the transcripts they produced.
JDK25=/path/to/jdk-25 JDK27=/path/to/jdk-27 [JDK21=/path/to/jdk-21] ./run.sh # regenerates output/*.txt
src/compiles and runs on 21, 25 and 27 (exceptUnnamed.java, which needs 22 or later).broken/fails to compile on purpose.preview/uses primitive patterns (JEP 532, preview in 27) and needs--enable-preview --release N.sep/is a sealed hierarchy compiled in two versions, to show the one runtime failure an exhaustiveswitchcannot prevent.
Tested on Temurin 25.0.4.1+1 and 27+35, and OpenJDK 21.0.10 for the baseline.