[JAVA] How to use @Builder and @NoArgsConstructor together

Task

An error occurs when @Builder and @NoArgsConstructor are used together as shown below.


@Builder
@NoArgsConstructor
public class MyName {
    private String first;
    private String last;
}

Solution

You can do this by including the @AllArgsConstructor annotation or by adding a constructor with all fields.


@Builder
@NoArgsConstructor
@AllArgsConstructor
public class MyName {
    private String first;
    private String last;
}

  ..Or..


@Builder
@NoArgsConstructor
public class MyName {
    private String first;
    private String last;

    MyName(String first, String last) { ... }
}

Recommended Posts

How to use @Builder and @NoArgsConstructor together
How to use OrientJS and OrientDB together
How to use @Builder (Lombok)
How to use StringBurrer and Arrays.toString.
How to use EventBus3 and ThreadMode
How to use equality and equality (how to use equals)
How to set up and use kapt
How to use substring and substr methods
How to use Map
How to use rbenv
How to use letter_opener_web
How to use with_option
How to use fields_for
How to use java.util.logging
How to use map
How to use collection_select
How to use active_hash! !!
How to use MapStruct
How to use hidden_field_tag
How to use TreeSet
[How to use label]
How to use identity
How to use JUnit 5
How to use Dozer.mapper
How to use Gradle
How to use org.immutables
How to use java.util.stream.Collector
How to use VisualVM
How to use Map
[Java] How to use FileReader class and BufferedReader class
[Ruby] How to use gsub method and sub method
How to use Segmented Control and points to note
How to use scope and pass processing (Jakarta)
[Java] How to use Calendar class and Date class
[Java] How to use Map
How to use Chain API
[Java] How to use Map
How to use Priority Queuing
[Rails] How to use enum
How to use java Optional
How to use JUnit (beginner)
How to use Ruby return
[Rails] How to use enum
[Swift] How to use UserDefaults
How to use Swift UIScrollView
How to use Big Decimal
[Java] How to use Optional ②
[Java] How to use removeAll ()
How to use String [] args
[Java] How to use string.format
How to use Java Map
Ruby: How to use cookies
How to use dependent :: destroy
How to use Eclipse Debug_Shell
How to use Apache POI
[Rails] How to use validation
How to use RealSense with ubuntu 20.04 and ROS Noetic
[Rails] How to use authenticate_user!
[Rails] How to use "kaminari"
How to use GC Viewer
[Java] How to use Optional ①