Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CISonatype CentralLicense

imcover.png

Full documentation atimmutables.org

Record Builder

@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);

Immutable class

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();

Changelog

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

Stars

Watchers

Forks

Packages

No packages published

Contributors83

Languages


[8]ページ先頭

©2009-2025 Movatter.jp