Pattern Matching in Java: Past, Present, Future
summary
Pattern matching becomes concrete: JDK 16 instanceof patterns introduces safe cast-and-bind; switch expressions with patterns (JDK 21) enables multi‑way, exhaustive branching over reference types and records; six JEPs drive the work via Project Amber. Primitive patterns arrive as a preview (JDK 23), adding magnitude/precision safeguards so casts no longer silently lose data. Proposals add deconstructors and withers for class construction/deconstruction, yielding composable serialization and compile‑time exhaustiveness that prevents many runtime ClassCastExceptions or unexpected variants.
AI-written summary · about
chapters (23)
- 0:00Introduction to patterns
- 1:41Traditional vs modern code
- 3:51Defining pattern matching
- 7:27Pattern matching evolution
- 10:28Instanceof patterns
- 13:11Switch statements limitations
- 15:21Switch expressions
- 17:03Patterns in switch
- 19:09Record patterns
- 21:53Sealed classes
- 24:12Exhaustiveness and safety
- 28:43Unnamed variables and patterns
- 32:40Primitives in patterns
- 35:28Safeguarding conversions
- 39:08Advanced pattern matching
- 42:05Improving APIs
- 44:35Record deconstruction
- 45:23Construction of classes
- 46:15Deconstruction of classes
- 48:14Record reconstruction
- 49:20Class reconstruction
- 50:31Serialization mechanism
- 52:45Conclusion
related talks
52mPattern Matching: Small Enhancement or Major Feature?
39mPattern Matching: Small Enhancement or Major Feature?
29mThe Art of Java Language Pattern Matching
46mThe Art of Java Type Patterns
38mPattern Matching in Java: Better Code, Better APIs
56mThe Art of Java Language Pattern Matching
27mPattern Matching for Java
50mPattern Matching in Java Deep Dive
