🌐
GitHub
github.com › Randgalt › record-builder
GitHub - Randgalt/record-builder: Record builder generator for Java records · GitHub
Can be used instead of new NameAndAge(...) */ public static NameAndAge NameAndAge(String name, int age) { return new NameAndAge(name, age); } /** * Return a new builder with all fields set to default Java values */ public static NameAndAgeBuilder ...
Starred by 921 users
Forked by 70 users
Languages   Java
🌐
How to do in Java
howtodoinjava.com › home › java basics › builder pattern for java records
Builder Pattern for Java Records
August 6, 2024 - This annotation generates a new class with a record name appended with “Builder”. For example, for User record, the generated builder class is UserBuilder.
Discussions

Java record does not have default builder - Stack Overflow
Add a concrete example of what is not possible. ... I suppose you're asking why they don't implement the builder pattern by default. ... This standalone project provides a great record builder solution github.com/Randgalt/record-builder. ... Recreating Lombok is not the purpose of Java record. More on stackoverflow.com
🌐 stackoverflow.com
レコードと @Builder : r/javahelp
🌐 r/javahelp
ANN: Record Builder (early access) for Java Records

I see a builder as vital to complete Java records. The JDK will get around to it eventually (and likely other tools) but I thought I'd add it now.

Example

@RecordBuilder  
public record NameAndAge(String name, int age){}

This will generate a builder class that can be used ala:

// build from components
var n1 = NameAndAgeBuilder.builder().name(aName).age(anAge).build();

// generate a copy with a changed value
var n2 = NameAndAgeBuilder.builder(n1).age(newAge).build(); // name is the same as the name in n1

// pass to other methods to set components
var builder = new NameAndAgeBuilder();
setName(builder);
setAge(builder);
var n3 = builder.build();
More on reddit.com
🌐 r/java
37
42
December 16, 2019
Records and @Builder
It does not defeat the purpose. Records are immutable data objects. How you initialize them, is up to you and using the builder pattern on big data objects makes sense as sometimes the default record constructor might be inflexible. If you don't want to use lombok (@Builder), this works great: https://github.com/Randgalt/record-builder More on reddit.com
🌐 r/javahelp
12
2
September 2, 2024
🌐
Java Code Geeks
javacodegeeks.com › home › core java
Java RecordBuilder Example - Java Code Geeks
August 13, 2025 - In the compact constructor of Employee, we enforce validation rules such as requiring a positive id, non-empty name and designation, and a non-null address, while defaulting department if not provided and ensuring the skills list is immutable via List.copyOf(). The Address record similarly validates its street, city, and zipCode fields. In the Main class, we use the generated builder() methods to construct Address and Employee instances, showing both a minimal creation with defaults and a fully populated example.
🌐
Baeldung
baeldung.com › home › java › a practical guide to recordbuilder in java
A Practical Guide to RecordBuilder in Java | Baeldung
November 12, 2025 - With a single annotation, we gain a fluent, safe, and readable way to build and modify record instances. It offers support for staged builders, withX() methods, customization hooks, and more – all while respecting immutability. For example, let’s suppose we annotate our record like this:
🌐
DEV Community
dev.to › agavrilov76 › record-companion-simple-builder-pattern-for-java-records-4h9f
Record Companion: Simple Builder Pattern for Java Records - DEV Community
September 21, 2025 - Record Companion focuses on simplicity and ease of use, making it perfect if you just want straightforward builder patterns without the extra bells and whistles. Java Records gave us immutable data structures. ValidCheck gave us clean validation.
🌐
Medium
medium.com › @sskmal › java-records-6736f45a6aa7
Java Records and Builder pattern For Record | by sunimal malkakulage | Medium
August 21, 2024 - Validation: You can add validation logic in the build() method or within individual setter methods in the builder, ensuring that only valid objects are constructed. While records are meant to be simple and straightforward, adding a builder class can make them more versatile, especially in more complex object construction scenarios.
🌐
Coderanch
coderanch.com › t › 776593 › code-reviews › engineering › Java-Record-Builder-Practice
Java Record Builder Best Practice (Code Reviews forum at Coderanch)
September 16, 2023 - Yeah - It seems like builders are normally done with an inner class, but I wondered if things might be done differently for Records. Another reason for using a builder is to be able to set values one-by-one from lambdas without having to use something like AtomicReference<String> with its set and get methods. For example - parsing YAML file contents using switch with lambda-style case clauses using a builder: Using AtomicReference:
Find elsewhere
🌐
Medium
medium.com › @trivajay259 › builder-pattern-for-java-records-f62d884e9973
Builder Pattern for Java Records. The builder pattern aims to provide a… | by Ajay Kumar | Medium
March 12, 2026 - public record Team(String name, String description, String uuid, String photoPath) { public static final class Builder{ String name; String description; String uuid; String photoPath; public Builder uuid(String uuid) { this.uuid = uuid; return ...
🌐
Java Guides
javaguides.net › 2023 › 12 › builder-pattern-with-java-records.html
Builder Pattern with Java Records
March 17, 2024 - The Builder Pattern comes to the rescue here. It allows step-by-step construction of complex objects and can be particularly useful when you have several optional parameters. Let's create an example to demonstrate combining Java Records with the Builder Pattern for a more flexible object creation ...
Top answer
1 of 1
23

Records are not “Lombok-lite”

Recreating Lombok is not the purpose of Java record.

The purpose of Java record is to provide an explicit vehicle for transparently communicating shallowly-immutable data.

Technically, records are Java’s nominal tuple. Tuple means an ordered set of fields. Nominal means the fields have names, as does their container. Practically, you can think of a Java record as a struct on steroids.

See the official document for scope and purpose, JEP 395: Records.

So no Builder feature need be provided by default as that lies outside the scope of Java record. However, you can easily create your own Builder for any particular record class.

AI-generated

Actually, you need not write your own Builder implementation. Let a generative AI draft the code on your behalf. (Be sure to review carefully as these AIs are imperfect.)

For example:

write code for a Builder class for the Java record record Person ( String name , LocalDate birth ){}

Ecosia AI chat feature produces:

public record Person(String name, LocalDate birth) {
    
    public static class Builder {
        private String name;
        private LocalDate birth;

        public Builder name(String name) {
            this.name = name;
            return this;
        }

        public Builder birth(LocalDate birth) {
            this.birth = birth;
            return this;
        }

        public Person build() {
            return new Person(name, birth);
        }
    }
}

That code worked for me, copy-pasted, with no edits needed.

Usage:

Person person = new Person.Builder()
    .birth(LocalDate.of(2001, Month.JANUARY, 23))
    .name("Alice")
    .build();

person.toString() // ➡️ Person[name=Alice, birth=2001-01-23]

Withers

By the way, work is underway to add “withers”, a feature to instantiate a new record object based on the payload values of another. See JEP 468: Derived Record Creation (Preview).

Jakarta Validation

You may want to use Jakarta Validation (previously known as Bean Validation) to verify the validity of your new record object’s state.

Likewise, you might use Jakarta Validation in your Builder implementation.

IDE code generation

Your IDE may have a feature for generating code for a Builder from a given Java Record.

For example, IntelliJ has a built-in feature Replace Constructor with Builder. However that does not work for Java Record. But there is a plugin for that. The Record Builder Plugin can “automatically generate builder classes for your Java Records, JavaBeans and Interfaces, allowing you to select fields and configure the generated builder”.

RecordBuilder library

RecordBuilder is an interesting project that lets you mark a Java record with an annotation. Then RecordBuilder generates code for builders and withers.

I’ve not yet tried using this library, so I cannot vouch for it.

🌐
Medium
medium.com › @pravin3c › 3-ways-to-create-builder-pattern-for-java-records-441cb3bc94b3
3 Ways to Create Builder Pattern for Java Records | by Pravin Choudhary | Medium
April 5, 2024 - The Builder pattern also allows for easy state validation by implementing or calling the validation logic in the build method, before the actual object is created. This avoids the creation of objects with an invalid state. Java Records are a concise way to create immutable data structures, automatically generating constructors, getters, and standard methods like equals(), hashCode(), and toString().
🌐
Oracle
docs.oracle.com › en-us › iaas › tools › java › latest › com › oracle › bmc › datalabelingservicedataplane › model › Record.Builder.html
Record.Builder (Oracle Cloud Infrastructure Java SDK - 3.90.0)
java.lang.Object · com.oracle.bmc.datalabelingservicedataplane.model.Record.Builder · Enclosing class: Record · public static class Record.Builder extends Object · clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait ·
🌐
Baeldung
baeldung.com › home › java › core java › custom constructor in java records
Custom Constructor in Java Records | Baeldung
January 15, 2026 - In this example, we created a list of StudentRecord objects that we could sort by name. Since name will never be null, we did not need to handle nulls while sorting. To sum up, custom constructors in Java records allow us to add additional logic ...
🌐
Sonar
sonarsource.com › blog › builders-withers-and-records-java-s-path-to-immutability
Builders, Withers, and Records - Java’s path to immutability | Sonar
February 21, 2024 - In order to achieve immutability we have different options like Builders, Withers, or the use of Record type, but ultimately, the choice between Builders and Withers depends on the specific requirements of your application and the design principles you want to follow. Builders are often preferred for complex object creation with many optional parameters, while withers can be more suitable for modifying existing immutable objects. If you are on Java 16 or above consider that the use of Records is recommended over ordinary classes as they are immutable per definition.
🌐
Softwaregarden
softwaregarden.dev › en › posts › new-java › records › vs-lombok-yet-again-with-builder-pattern
Java Records tortured with Lombok yet again (builder edition) – SoftwareGarden.dev
April 15, 2021 - Or just stick to JavaBeans. However, maybe there are still other ways to “exploit” Lombok with records and bring it to another level? Maybe this time it could be even somewhat useful? Short answer: no. Currently, there’s no ‘default’ or ‘standard’ builder for records.
🌐
javaspring
javaspring.net › blog › java-records-builder
Java Records Builder: A Comprehensive Guide — javaspring.net
Lombok automatically generates the builder code for the Person record. When implementing a builder manually, it is common to use a fluent interface. A fluent interface means that each method in the builder returns the builder instance itself (this). This allows you to chain method calls together, making the code more readable. For example:
🌐
DZone
dzone.com › coding › java › migrating from lombok to records in java
Migrating From Lombok to Records in Java
December 28, 2023 - Records offer better integration with the language and are supported natively by various tools and frameworks. ... In the record example, we define a Movie class with two fields (title and releaseYear) in the constructor parameter list.
🌐
Steinar Bangs blogg
steinar.bang.priv.no › 2024 › 05 › 10 › build-java-records-with-builders
Build Java records with builders | Steinar Bangs blogg
May 12, 2024 - So to be clear: transient properties method names should follow the convention of Java beans getters: ... So e.g. if you have a property “fullName”, the method name should be “getFullName”. The jackson maintainer considers serializing transient getters as fiels a feature (and so do I, since it let me keep my generated properties when moving from beans to records). ... Like Loading... Pingback: Build beans better with builders | Steinar Bangs blogg