Record Patterns - Going Beyond Records - A Deep Dive
summary
Java 21 standardizes the Record Pattern feature and the companion Switch Pattern, demonstrates how compilers lower patterns to an invokedynamic type switch with a bootstrap array of concrete types, and shows deconstruction extracting record components (including nested records and inferred types). Concrete gotchas include dominating case order, no multi-case pattern lists, no fall-through, record patterns not allowed in for-each, and null handling wired through a match exception wrapper that uses record accessors under the hood.
AI-written summary · about
chapters (14)
- 0:00Record patterns overview
- 1:31Records as constant classes
- 6:06Records for data modeling
- 7:58Switch statement limits
- 9:55Type switches bytecode
- 15:20When keyword in switches
- 20:42Switch pattern errors
- 23:23Sealed classes with records
- 27:26Record deconstruction patterns
- 29:12Exhaustive switch expressions
- 31:51Record pattern restrictions
- 32:54Record patterns in loops
- 33:39Null handling in records
- 36:32Q&A
related talks
50mPattern Matching in Java Deep Dive
56mThe Art of Java Language Pattern Matching
38mPattern Matching in Java: Better Code, Better APIs
33mImprove your Java Applications with Records and Pattern Matching
54mData Oriented Programming with the JDK 19
54mData Focused programming with Pattern Matching in Java
46mThe Art of Java Type Patterns
46mThe Art of Java Type Patterns
