Why this matters
- Sealed types, records and pattern matching were designed as one feature in three parts. This article is where they combine, and it is the finished form of data-oriented Java.
- Destructuring removes the accessor noise from code that walks a data structure, which is most parsing, interpreting and transforming code.
- Exhaustive switches mean adding a case to your model produces a list of compile errors telling you exactly what to update.
Patterns in switch
Loading compiler…
Loading compiler…
Null in switch
This is a genuine behaviour change worth knowing precisely.
Loading compiler…
Record patterns
A record pattern matches the type and binds the components by position.
Loading compiler…
Object oUnknown type
x1Nested component
y1Nested component
p2Whole record
Nested patterns
This is where destructuring earns its place.
Loading compiler…
Loading compiler…
The rest of this guide is part of Pro
Free covers every fresher guide in full. Pro unlocks Senior, Staff and Architect guides across every track.
Still to come · 5 sections
- Guarded patterns with when
- A worked example: a small expression evaluator
- Design guidance
- Unnamed patterns
- Common misreadings
Test yourself
Answer these before moving on — recall is what makes it stick.