Is Record feature in Java 16 is an alternative to builder classes?

Basically ... no it isn't.

Records provide immutability to an object, so does builder pattern.

That's not correct. The builder pattern can be applied to both immutable and mutable objects. It is actually about how objects are created rather than the nature of the objects themselves.

What are pros and cons of using record in place of builder?

Well, simply put, you can't use records as a replacement for the builder pattern ... because they do different (in fact, orthogonal) things. Here's a point by point comparison of conventional Java classes implemented with the builder pattern versus record types:

  • Mutability:
    • class + builder - either mutable or immutable objects can be created
    • record - immutable only
  • Validation:
    • class + builder - yes ... the builder can validate the arguments incrementally or in the build() method.
    • record - yes ... in constructors
  • Supports optional parameters:
    • class + builder - yes
    • record - no ... though you can implement overloaded constructors
  • Supports extends:
    • class + builder - yes
    • record - no ... though you can use default methods from an inherited interface.
  • Supports internal state / abstraction:
    • class + builder - yes
    • record - no
  • Less boilerplate code:
    • class + builder - yes (relative to classes implemented without a builder) and no (relative to records).
    • record - yes

The "less boilerplate" issue is nuanced. On the one hand a builder avoids the need for overloaded constructors or new calls with huge numbers of parameters. (But you need to implement the builder itself ... which is mostly boilerplate.) On the other hand a record can be implemented without any explicit methods and a simple record constructor with no body.

Answer from Stephen C on Stack Overflow
🌐
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 builder() { return new NameAndAgeBuilder(); } /** * Return a new builder with all fields set to the values taken from the given record instance */ public static NameAndAgeBuilder builder(NameAndAge from) { return new NameAndAgeBuilder(from.name(), from.age()); } /** * Return a "with"er for an existing record instance */ public static NameAndAgeBuilder
Starred by 921 users
Forked by 70 users
Languages   Java
🌐
Fxis.ai
fxis.ai › home › how to use recordbuilder in java 17
How to Use RecordBuilder in Java 17 fxis.ai
June 2, 2024 - An annotation to generate a Java record from an interface template. To start using RecordBuilder, you must first have the appropriate dependency included in your project. <dependency> <groupId>io.soabase.record-builder</groupId> <artifactId...
Discussions

Java record does not have default builder - Stack Overflow
Java came with records which are really useful and can avoid use of library like Project Lombok. But can someone please help me understand why records does not support Builder pattern by default? I More on stackoverflow.com
🌐 stackoverflow.com
lombok - Java Record with @Builder.Default - Stack Overflow
This case just shows the limitations of Java records, they are nice for simple cases, but not convenient for others. If someone uses a Builder, that is because it's a common pattern that facilitates object creation. 2025-06-09T14:31:23.913Z+00:00 ... Record constructors don't have defaults. The correct result depends upon the purposes of the developer writing the code. 2025-06-23T21:17... More on stackoverflow.com
🌐 stackoverflow.com
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
ANN: Record Builder – Builder and Withers for Java 16 Records

I've mentioned this here before but now that Java 16 is released I've made a new release compiled with the latest Java 16.

Java 16 introduces Records. While this version of records is fantastic, it's currently missing some important features normally found in data classes: a builder and "with"ers. This project is an annotation processor that creates:

  • a companion builder class for Java records

  • an interface that adds "with" copy methods

  • an annotation that generates a Java record from an Interface template

More on reddit.com
🌐 r/java
8
30
March 16, 2021
Top answer
1 of 2
18

Is Record feature in Java 16 is an alternative to builder classes?

Basically ... no it isn't.

Records provide immutability to an object, so does builder pattern.

That's not correct. The builder pattern can be applied to both immutable and mutable objects. It is actually about how objects are created rather than the nature of the objects themselves.

What are pros and cons of using record in place of builder?

Well, simply put, you can't use records as a replacement for the builder pattern ... because they do different (in fact, orthogonal) things. Here's a point by point comparison of conventional Java classes implemented with the builder pattern versus record types:

  • Mutability:
    • class + builder - either mutable or immutable objects can be created
    • record - immutable only
  • Validation:
    • class + builder - yes ... the builder can validate the arguments incrementally or in the build() method.
    • record - yes ... in constructors
  • Supports optional parameters:
    • class + builder - yes
    • record - no ... though you can implement overloaded constructors
  • Supports extends:
    • class + builder - yes
    • record - no ... though you can use default methods from an inherited interface.
  • Supports internal state / abstraction:
    • class + builder - yes
    • record - no
  • Less boilerplate code:
    • class + builder - yes (relative to classes implemented without a builder) and no (relative to records).
    • record - yes

The "less boilerplate" issue is nuanced. On the one hand a builder avoids the need for overloaded constructors or new calls with huge numbers of parameters. (But you need to implement the builder itself ... which is mostly boilerplate.) On the other hand a record can be implemented without any explicit methods and a simple record constructor with no body.

2 of 2
-1

The JDK Enhancement Proposal describes records as “classes that act as transparent carriers for immutable data”.

Use cases:

Reduces Boilerplate code: Historically, creating immutable objects in Java was rather painful work, records takes care of almost all of that work for us. Records also allows the class to be better focused on the business problem at hand by reducing boilerplate code. This makes it a compelling feature for implementing things like DDD-style Value Objects and Domain Events.

public record Address(String street, String postCode, String town, String country) {
}

Temporary containers of data: Records can be defined not only as stand-alone classes, but also locally inside a method. This makes them useful as temporary containers during data processing, for quickly creating ephemeral mock data in tests, etc. We will see an example of this below.

Data Validation: Records provide support for different validation. it reduces responsibilities from the developer to write such validation

@NonNull -> a field can not be null.      
@Min() -> a min value that a field can hold.  
@Max() -> a max value that a field can hold.
@GreaterThanZero -> a field can not have value less than or equal to zero.

Comparison to Builder Classes: The only advantage that a record class offers over builder classes is data validation.

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.

🌐
How to do in Java
howtodoinjava.com › home › java basics › builder pattern for java records
Builder Pattern for Java Records
August 6, 2024 - The builder pattern aims to provide a flexible solution for constructing complex data structures by separating the build process from the final representation of the data structure.
🌐
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 - Validating the input parameters is covered by using a "custom constructor" in the record declaration. In your code it would look something like this: So that should take care of the validation part. That leaves the Builder to provide the fluid interface, which looks like it can't be made compulsory but maybe that isn't as much of a problem.
🌐
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.
Find elsewhere
🌐
Oracle
docs.oracle.com › en › java › javase › 17 › language › records.html
6 Record Classes - Java
October 20, 2025 - Record classes, which are a special kind of class, help to model plain data aggregates with less ceremony than normal classes.
🌐
Oracle
docs.oracle.com › en › java › javase › 17 › docs › api › java.base › java › lang › Record.html
Record (Java SE 17 & JDK 17)
April 21, 2026 - A record class is a shallowly immutable, transparent carrier for a fixed set of values, called the record components. The Java language provides concise syntax for declaring record classes, whereby the record components are declared in the record header.
🌐
Medium
brett-fisher.medium.com › java-records-and-lombok-in-practise-37447cd22415
Java Records and Lombok in practise | by Brett Fisher | Medium
September 28, 2021 - Spring has a milestone version (2.6.0-M3), that will soon be released, that supports JDK 17 features. Jackson has added support in 2.12. Lombok with IntelliJ does not index created builder methods — tests still pass. This article covers some of key aspects of records, using Lombok, the differences and interoperability. Making the most of the new java features whilst not loosing the benefits of using Lombok.
🌐
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 - It allows step-by-step construction of complex objects and can be particularly useful when you have several optional parameters. Java record types being immutable, by default, the builder pattern is an excellent match for records.
🌐
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 ·
🌐
InfoQ
infoq.com › articles › exploring-java-records
Exploring Java Records beyond Data Transfer Objects - InfoQ
June 19, 2023 - At the end of our immutable entity with a Record, we'll also include the change method, where we need to change the book to a new edition. In the next step, we'll see the creation of the second edition of the well-known book by Joshua Bloch, Effective Java. Thus, we cannot change the fact that there was once a first edition of this book; this is the historical part of our library business. Book first = Book.builder().id("id").title("Effective Java").release(Year.of(2001)).builder(); Book second = first.newEdition("id-2", Year.of(2009));
🌐
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.
🌐
TheServerSide
theserverside.com › video › How-Java-17-records-work
How Java 17 records work | TheServerSide
record Location(double latitude, double longitude) { } To demonstrate how a Java 17 record can help you create cleaner and simpler code, let's first start off with a standard, simple Java class that can identify a person's location, find a center-point when multiple locations are provided, or even find clusters within a data set.
🌐
Java Guides
javaguides.net › 2023 › 12 › builder-pattern-with-java-records.html
Builder Pattern with Java Records
March 17, 2024 - ▶️ Subscribe to My YouTube Channel (178K+ subscribers): Java Guides on YouTube · ▶️ For AI, ChatGPT, Web, Tech, and Generative AI, subscribe to another channel: Ramesh Fadatare on YouTube · Java Records, introduced in Java 14, simplified the definition of immutable data classes. While records simplify data class creation, combining them with the Builder ...
🌐
Reddit
reddit.com › r/java › ann: record builder – builder and withers for java 16 records
r/java on Reddit: ANN: Record Builder – Builder and Withers for Java 16 Records
March 16, 2021 - FYI https://github.com/Randgalt/record-builder/pull/28 ... FYI - version 26 was just released. Recent features include: ... News, Technical discussions, research papers and assorted things of interest related to the Java programming language NO programming help, NO learning Java related questions, NO installing or downloading Java questions, NO JVM languages - Exclusively Java
🌐
Baeldung
baeldung.com › home › java › core java › java record keyword
Java Record Keyword | Baeldung
November 5, 2025 - Records are immutable data classes that require only the type and name of fields. The equals, hashCode, and toString methods, as well as the private, final fields and public constructor, are generated by the Java compiler.