Auto generate constructors in Java object using Lombok

 What is Lombok?

Lombok is a Java library that auto generates lots of boiler plate code for Java classes. Lombok works at compile time and manipulates Java byte code to add additional features. Lombok uses annotations to specify what boiler plate code will be generates.

Using @AllArgsConstructor and @NoArgsConstructor annotations.

Lombok provides an @AllArgsConstructor annotation to auto generate a constructor containing all the fields defined in a Java object. @AllArgsConstructor can be applied to a Java class.

Lombok also provides a @NoArgsConstructor annotation that when applied to a class, with generate a default constructor without any parameters.

See below example on how to generate and use constructors using Lombok.

All the posts in this blog have a working example. Please visit our Github repository

0 comments:

Post a Comment