A small Java library to make working with immutable Java Records easier.
It provides a convenient with method for records to modify single fields immutably.
Add the dependency from Maven Central:
<dependency>
<groupId>io.github.mrtimeey</groupId>
<artifactId>record-wither</artifactId>
<version>${record-wither.version}</version>
</dependency>
import io.github.mrtimeey.records.Withable;
public record User(String name, int age) implements Withable<User> {}
User user = new User("Alice", 30);
// Change one field immutably
User older = user.with(User::age, 31);
System.out.println(older); // User[name=Alice, age=31]
Records in Java are immutable by design.
While this is great, it means that modifying a single field requires calling the constructor with all parameters again.
record-wither
provides an easy way to do this, inspired by "with" methods in other languages.
- Built with Java 17+
- Tested with JUnit 5 and AssertJ
- Published to Maven Central
Run the tests:
mvn clean verify
This project is licensed under the MIT License.
Contributions are welcome! 🎉
Please read the Contributing Guidelines for details on our development process, coding standards, and how to propose changes.
By participating in this project, you are expected to uphold our Code of Conduct.