OpenJDK's Project Amber has proposed "carrier classes" and "carrier interfaces" to extend record-like capabilities to more flexible Java class designs. While records (introduced in Java 16) provide concise immutable data modeling with auto-generated methods and pattern matching support, they have strict constraints that limit their use in real-world scenarios requiring derived values, caching, mutability, or inheritance. Carrier classes would allow developers to define a state description similar to records while maintaining the flexibility of traditional classes, enabling patterns like cached computed values and alternative internal representations. The proposal also introduces carrier interfaces for pattern matching across implementations. This exploratory design note aims to reduce boilerplate and support Java's shift toward data-oriented programming, though no concrete syntax or release timeline has been announced.
Sort: