Pattern Matching in Java
summary
Shows how Java replaces long conditional chains — recalled 169 if-else — with actual value-returning switch expression syntax using arrows and yield, and demonstrates object pattern matching via instanceof with inline variable binding. Uses records plus sealed interfaces to avoid defaults, illustrates guarded patterns (e.g., sell quantity >= 5,000 triggers audit), dominance checks by the compiler, destructuring of records, and notes Java 22 adds underscore wildcards; examples compile and run, with the compiler inserting a runtime-default if enums expand without recompilation.
AI-written summary · about
chapters (9)
- 0:00Introduction to pattern matching
- 5:43Switch statements vs expressions
- 10:02Switch expressions explained
- 16:08Switch completeness and defaults
- 22:34Pattern matching with instance of
- 35:51Data-oriented programming with pattern matching
- 41:28Sealed classes and records
- 53:28Destructuring in Java
- 59:24Java 22 features and underscore
related talks
39mPattern Matching: Small Enhancement or Major Feature?
50mPattern Matching in Java Deep Dive
29mThe Art of Java Language Pattern Matching
56mThe Art of Java Language Pattern Matching
52mPattern Matching: Small Enhancement or Major Feature?
38mPattern Matching in Java: Better Code, Better APIs
27mPattern Matching for Java
54mPattern Matching in Java: Past, Present, Future
