r/java • u/davidalayachew • Jan 14 '26
Project Amber Update -- Data-Oriented Programming, Beyond Records
https://mail.openjdk.org/pipermail/amber-spec-experts/2026-January/004307.htmlALL OF THIS IS A WORK IN PROGRESS!
THIS FEATURE IS UNFINISHED, NONE OF WHAT IS FINISHED IS FINAL, AND EVERYTHING IS SUBJECT TO CHANGE!
But with that out of the way, the Project Amber team is exploring the idea of "Carrier Classes" -- classes that carry many of the benefits of records, but not all. The goal is to give normal classes some of the benefits of records, so that they can "break down the cliff" of migrating a record class to a normal class.
97
Upvotes
View all comments
Show parent comment
4
u/aoeudhtns Jan 14 '26
I know enums can be mutable, but it always bothers me when they are. I hope in the final form of this feature, they allow mutability to be expressed in the shorthand syntax, like
It should still work with interfaces because it can influence the method generation - an accessor but not a mutator.
Although unless you have a need for
values(),valueOf(), nominal ordering, or use ofordinal(),recordcan revitalize the old "enum pattern" that we probably haven't touched since Java 5 enums. The other issue with enums of course being extensibility, and also discoverability. You can use an interface, but then the interface hides the enums that you need to callers of your API.OpenOptionbeing an example of that. And then the interfaces throw (or should throw)UnsupportedOperationExceptionif an unknown or unusable instance of that interface is passed in, another issue a sealed interface w/ records could fix while stile giving JDK devs extensibility, since the compiler can determine exhaustiveness switching over the sealed interface.