Paul Krill
Editor at Large

Java proposal would streamline record creation

news
Jan 29, 20242 mins

Derived record creation would allow developers to create a new record from an existing record, updating only the values that need to change.

3 replication bulldogs twin
Credit: Thinkstock

In an effort to streamline code, Java would be enhanced with derived record creation, via a proposal that would provide a means to create record instances from existing records through a block of transformation code.

The OpenJDK proposal authored by Oracle technical staff, titled “Derived Record Creation,” would streamlinescode by deriving a new record from an existing record, updating only components that need to change. The proposal notes that because records are immutable values, developers frequently build new records to reflect new data. The feature would enter Java in a preview state.

Goals of the proposal include providing a concise means to create new record instances derived from existing record values, and streamlining the declaration of record classes by eliminating the need to provide explicit “wither” methods. Wither methods are similar to setter methods but for immutable classes.

It is not a goal, the proposal states, to support a distinguished class of wither methods or to provide a Pascal-style with construct that simplifies access to arbitrary complex expressions. It also is not a goal to provide derived instance creation expressions for ordinary, non-record class values, although that may be the subject of a future JEP (JDK Enhancement Proposal).

In explaining the motivation for derived record creation, the proposal notes that the immutability of record classes gives both safety and predictability, and enables a number of features that make them easy to use. However, the systems that developers need to model have state, and evolving state modeled by record classes can be cumbersome. Derived creation provides a succinct way to update the components of record classes when the underlying state changes.

Derived record creation would be part of the Standard Edition (SE) of Java. No specific version of Java SE is cited in the proposal yet as a target for the capability. The current version of standard Java is JDK 21, with successor JDK 22 due in March, with its feature set already frozen. JDK 23 is expected in September.

Paul Krill

Paul Krill is editor at large at InfoWorld. Paul has been covering computer technology as a news and feature reporter for more than 35 years, including 30 years at InfoWorld. He has specialized in coverage of software development tools and technologies since the 1990s, and he continues to lead InfoWorld’s news coverage of software development platforms including Java and .NET and programming languages including JavaScript, TypeScript, PHP, Python, Ruby, Rust, and Go. Long trusted as a reporter who prioritizes accuracy, integrity, and the best interests of readers, Paul is sought out by technology companies and industry organizations who want to reach InfoWorld’s audience of software developers and other information technology professionals. Paul has won a “Best Technology News Coverage” award from IDG.

More from this author