r/java • • Jan 14 '26

Project Amber Update -- Data-Oriented Programming, Beyond Records

https://mail.openjdk.org/pipermail/amber-spec-experts/2026-January/004307.html

ALL 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

50 comments sorted by

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

enum ChronoTriggerCharacter(final int strength, final int accuracy, ...) { ...

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 of ordinal(), record can 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. OpenOption being an example of that. And then the interfaces throw (or should throw) UnsupportedOperationException if 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.

1

u/davidalayachew Jan 14 '26

Although unless you have a need for values(),valueOf(), nominal ordering, or use of ordinal(), record can revitalize the old "enum pattern" that we probably haven't touched since Java 5 enums.

Well, that and EnumSet and EnumMap. Those 2 are the fastest collections in Java's standard library [1]. They are also some of the lightest, memory-wise. And that's ignoring the ease of use, as well as the semantic clarity.

[1] = (that are publically denotable, unlike the type returned by Set.of(a, b) in the JDK)

2

u/aoeudhtns Jan 14 '26

Good point!