r/java • u/davidalayachew • Jan 09 '26
Project Amber Status Update -- Constant Patterns and Pattern Assignment!
https://mail.openjdk.org/pipermail/amber-spec-experts/2026-January/004306.html
65
Upvotes
View all comments
Show parent comment
0
u/manifoldjava Jan 11 '26
Code that must be mentally rewritten before it can be understood is, by definition, harder to read.
To understand just
User(_, ADMIN)the reader must perform three mandatory mental steps:role_refers tonameThere's no getting around this even for a familiar reader.
Understanding this requires zero mental reconstruction. The field being tested is spelled out, the semantic role is explicit, and no positional mapping is required.
Destructuring works naturally in languages whose core model is algebraic or tuple-based. Java is nominal and name-based, so positional deconstruction discards information the language otherwise treats as essential.
Re exhaustiveness: it’s a property of variants, not fields. Records are product types, not sum types. Exhaustive checking on a record just asks, "Did I list all the cases I listed?" - meaningless.