https://github.com/immutables/immutables
Java annotation processor to create immutable objects and builders, for records too. Sweep boilerplate code under the rug!
https://github.com/immutables/immutables
annotation-processor builder gson guava immutable-collections immutable-datastructures immutable-objects immutables jackson java records
Last synced: 13 days ago
JSON representation
Java annotation processor to create immutable objects and builders, for records too. Sweep boilerplate code under the rug!
- Host: GitHub
- URL: https://github.com/immutables/immutables
- Owner: immutables
- License: apache-2.0
- Created: 2013-07-07T13:48:23.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2025-12-28T17:55:31.000Z (27 days ago)
- Last Synced: 2025-12-31T07:30:54.214Z (24 days ago)
- Topics: annotation-processor, builder, gson, guava, immutable-collections, immutable-datastructures, immutable-objects, immutables, jackson, java, records
- Language: Java
- Homepage: http://immutables.org
- Size: 13.6 MB
- Stars: 3,540
- Watchers: 82
- Forks: 291
- Open Issues: 437
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-ccamel - immutables/immutables - Java annotation processor to create immutable objects and builders, for records too. Sweep boilerplate code under the rug! (Java)
README
 [](https://maven-badges.sml.io/sonatype-central/org.immutables/value/) [](https://opensource.org/licenses/Apache-2.0)

Full documentation at [immutables.org](http://immutables.org)
## Record Builder
```java
@Value.Builder
record Person(String name, int age, String email) {}
// Use the generated builder
Person person = new PersonBuilder()
.name("Alice")
.age(30)
.email("alice@example.com")
.build();
```
More fancy example having copy-with methods generated, and style `withUnaryOperator="with*"`
```java
@Value.Builder
record Person(String name, int age) implements WithPerson {
// Extend the generated PersonBuilder
static class Builder extends PersonBuilder {}
}
// Use your custom builder
var person = new Person.Builder()
.name("Bob")
.age(18)
.build();
person = person.withName("Bobby!")
.withAge(age -> age + 3);
```
## Immutable class
Minimal, classical style
```java
@Value.Immutable
interface Book {
String isbn();
String title();
List authors();
}
ImmutableBook book = 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 extending `With*` interface
```java
// Define abstract value type using interface, abstract class or annotation
@Value.Immutable
public interface ValueObject extends WithValueObject {
// WithValueObject is not yet generated, We extend With* to inherit `with*` method signatures
String name();
List counts();
Optional description();
class Builder extends ImmutableValueObject.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 builder
var value = new ValueObject.Builder()
.name("Nameless")
.description("present")
.addCounts(1)
.addCounts(2)
.build();
value = value.withName("Doe");
//fetch values via accessors
List counts = v.counts();
Optional description = v.description();
```
## Changelog
See [releases](https://github.com/immutables/immutables/releases) tab for release history. Archived [changelog](.archive/CHANGELOG.md) for earlier releases.