The Three Amigos: Intermixing Pattern Matching, Records, and Sealed Classes
summary
Java now gives records give ctor/getters/toString/equals/hashCode so simple data holders are immutable and final; sealed permits clause enforces closed hierarchies so only listed subclasses compile and children must be final/sealed/non-sealed; pattern matching upgrades switch into an expression with guarded cases, dominance checks, and deconstruction of record components; combining all three lets the compiler prove exhaustiveness (no default needed) or emit a DefaultMatchException in stray runtime cases; the demo builds buy/sell records + sealed trade and the examples compile and run as shown.
AI-written summary · about
chapters (11)
- 0:00Introduction to three amigos
- 1:04Records as data carriers
- 15:13Records immutability and usage
- 16:14Sealed classes and interfaces
- 26:12Sealed hierarchy modifiers
- 35:49Pattern matching basics
- 46:30Guards and dominance in pattern matching
- 48:47Compiler trade-offs in pattern matching
- 49:07Interplay of features in practice
- 56:55Records with sealed classes
- 1:00:52Data-oriented programming summary
related talks
18mEnums on steroids - let's look at sealed classes!
56mThe Art of Java Language Pattern Matching
54mData Focused programming with Pattern Matching in Java
33mImprove your Java Applications with Records and Pattern Matching
31mData Oriented Programming and Matching in Java
38mPattern Matching in Java: Better Code, Better APIs
01h 01mPattern Matching in Java
43mEnums on steroids - let's look at sealed classes!
