The Art of Java Language Pattern Matching
summary
Explains how Java now binds pattern variables in instanceof and switch, showing actual code shapes: type patterns with automatic cast, guarded patterns using when (added around JDK 19/20), explicit record patterns for deconstruction, composable nested patterns, and unnamed variables (_ and var) finalised in JDK 21/22. Covers case null, primitive-array cases (primitives await Valhalla), sealed-class completeness to avoid defaults, and compile-time pattern dominance rules that reject unreachable cases. Claims concrete benefits: fewer casts/boilerplate, clearer deconstruction, and potential JIT optimizations as the runtime adapts.
AI-written summary · about
chapters (8)
- 0:00Introduction to pattern matching
- 2:11Instance of pattern matching
- 9:36Switch pattern matching
- 15:16Sealed classes and completeness
- 16:24Guarded patterns in switch
- 20:40Record pattern matching
- 25:15Unnamed variables and patterns
- 27:42Summary and future features
related talks
56mThe Art of Java Language Pattern Matching
46mThe Art of Java Type Patterns
46mThe Art of Java Type Patterns
39mPattern Matching: Small Enhancement or Major Feature?
54mPattern Matching in Java: Past, Present, Future
50mPattern Matching in Java Deep Dive
55mThe Art of Java Language Pattern Matching
52mPattern Matching: Small Enhancement or Major Feature?
