- Notifications
You must be signed in to change notification settings - Fork290
Java annotation processor to create immutable objects and builders, for records too. Sweep boilerplate code under the rug!
License
NotificationsYou must be signed in to change notification settings
immutables/immutables
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Full documentation atimmutables.org
@Value.BuilderrecordPerson(Stringname,intage,Stringemail) {}// Use the generated builderPersonperson =newPersonBuilder() .name("Alice") .age(30) .email("alice@example.com") .build();
More fancy example having copy-with methods generated, and stylewithUnaryOperator="with*"
@Value.BuilderrecordPerson(Stringname,intage)implementsWithPerson {// Extend the generated PersonBuilderstaticclassBuilderextendsPersonBuilder {}}// Use your custom buildervarperson =newPerson.Builder() .name("Bob") .age(18) .build();person =person.withName("Bobby!") .withAge(age ->age +3);
Minimal, classical style
@Value.ImmutableinterfaceBook {Stringisbn();Stringtitle();List<String>authors();}ImmutableBookbook =ImmutableBook.builder() .isbn("978-1-56619-909-4") .title("The Elements of Style") .addAuthors("William Strunk Jr.","E.B. White.") .build();
"sandwich" style, with nested builder and extendingWith* interface
// Define abstract value type using interface, abstract class or annotation@Value.ImmutablepublicinterfaceValueObjectextendsWithValueObject {// WithValueObject is not yet generated, We extend With* to inherit `with*` method signaturesStringname();List<Integer>counts();Optional<String>description();classBuilderextendsImmutableValueObject.Builder {}// ImmutableValueObject.Builder will be generated and// our builder will inherit and reexport methods as its own.// Static nested Builder will inherit all the public method// signatures of ImmutableValueObject.Builder}// Use generated immutable implementation and buildervarvalue =newValueObject.Builder() .name("Nameless") .description("present") .addCounts(1) .addCounts(2) .build();value =value.withName("Doe");//fetch values via accessorsList<Integer>counts =v.counts();Optional<String>description =v.description();
Seereleases tab for release history. Archivedchangelog for earlier releases.
About
Java annotation processor to create immutable objects and builders, for records too. Sweep boilerplate code under the rug!
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
No packages published
Uh oh!
There was an error while loading.Please reload this page.
