Enums on steroids - let's look at sealed classes!
summary
A loan-evaluator example implements three distinct outcomes—approve, refuse, suspend—using Java records, pattern matching, and sealed interfaces so the compiler enforces exhaustiveness and eliminates casts; switch with arrow labels and guarded patterns handles nuanced approval subcases (full vs reduced amount); record deconstruction pulls fields into case labels; unnamed patterns let unused values be skipped. Code migrates off Lombok and compiles on modern JDKs (Java 17–23), but preview features like string templates remain unstable and can change.
AI-written summary · about
chapters (14)
- 0:00Introduction and welcome
- 2:29About the speaker
- 3:11Business case: loan engine
- 8:09Modeling the response system
- 14:28Problems with legacy code
- 16:13Modernizing with Java 13
- 17:16Records for immutable classes
- 20:49Pattern matching in switch
- 26:34Guarded pattern matching
- 29:52Sealed classes and interfaces
- 35:49Java 21 features
- 37:53Java 23 unnamed patterns
- 40:26Future of Java features
- 41:28Why learn new Java features
related talks
38mEnums on steroids - let's look at sealed classes !
18mEnums on steroids - let's look at sealed classes!
01h 02mThe Three Amigos: Intermixing Pattern Matching, Records, and Sealed Classes
01h 01mDesigning with Sealed Classes
32mGetting the Most from Modern Java
55mPain-free Functional Programming with Java 21
46mThe Art of Java Type Patterns
50mModern Java Puzzlers
