@Value.Builder
record Player(int id, String name, boolean active)
implements WithPlayer {} Player player = new PlayerBuilder()
.id(11)
.name("Constantine")
.active(true)
.build(); Player copy = player
.withId(1)
.withName("Variant")
.withActive(false); @Value.Immutable
interface Book {
String isbn();
String title();
List<String> authors();
} ImmutableBook book = ImmutableBook.builder()
.isbn("978-1-56619-909-4")
.title("The Elements of Style")
.addAuthors("William Strunk Jr.", "E.B. White.")
.build(); ImmutableBook copy = book.withTitle("Whatever"); @Value.Immutable(intern = true, prehash = true)
abstract class Descriptor {
abstract String key();
abstract Optional<String> comment();
@Value.Redacted abstract String secret();
@Value.NaturalOrder
abstract NavigableSet<String> tags();
@Value.Derived int derivedCode() {
return key().hashCode() ^ secret().hashCode();
}
@Value.Lazy Access access() {
return Access.createFor(key(), secret());
}
} Sweep boilerplate under the rug like a pro.
Generate consistent and thread-safe immutable implementations
for abstract classes and interfaces. Builders for records,
immutable classes, factory methods, and plain constructors.
Generated code looks nice, a lot better than typical generators.
Adapt to your coding style and conventions. Naming templates allows for get*, with*, Abstract*, or I*
patterns to be used. Dozens of styles and feature toggles — generate as much or as little
as you need. Use custom immutable annotations. Use encodings to integrate custom types
and containers.
Feature Packed. Many ways to handle attributes: compute derived, lazy and default values; exclude from equality, or redact from toString. Nullable, Optional and Collection attributes.
Immutables are serialization ready. JSON integration via Jackson (v2 and v3), and Gson libraries.