Home > AI > Backend > SpringBoot > Lombok >

@NoArgsConstructor

Official website: https://projectlombok.org/features/constructor

@NoArgsConstructor will generate a constructor with no parameters.

@NoArgsConstructor(force = true) is used, then all final fields are initialized with 0 / false / null

Example code:

DataExample.java

@NoArgsConstructor
public class DataExample {
    public String name;
    public String handbook;
}

DemoApplication.java

DataExample d = new DataExample();
System.out.println(d.name);
System.out.println(d.handbook);

Leave a Reply