Add sealed module: modelling domains with sealed types and exhaustive switch

Payment model, permits and the three modifiers, default-branch trap, generic and recursive hierarchies, visitor comparison, run-time enforcement, modules. Transcripts from JDK 21, 25 and 27.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01TF9JWFvJSNm6HVzswzZU5a
This commit is contained in:
Claude
2026-09-24 12:03:59 +00:00
parent 65a4bbbbe3
commit ff6130bede
38 changed files with 638 additions and 0 deletions
+15
View File
@@ -0,0 +1,15 @@
# sealed — Sealed classes and interfaces
Companion code for the ankurm.com article **Sealed Classes and Interfaces: Modelling Domains with Exhaustive switch**. The explanation lives in the
article; this folder holds the runnable sources and the transcripts they produced.
```bash
JDK25=/path/to/jdk-25 JDK27=/path/to/jdk-27 [JDK21=/path/to/jdk-21] ./run.sh # regenerates output/*.txt
```
- `src/` compiles and runs unchanged on 21, 25 and 27: the `Payment` model, the three subclass modifiers, generic and recursive hierarchies, the `default` trap and a visitor for comparison.
- `broken/` fails to compile on purpose (one rule per file).
- `sep/` shows what the JVM itself enforces when a class file disagrees with the sealed type it claims to extend.
- `multi/` is a named module, the only place a sealed hierarchy may span packages.
Tested on Temurin 25.0.4.1+1 and 27+35, and OpenJDK 21.0.10 as the baseline.