Skip to content

CT Project Lombok

kapilkalra04 edited this page Mar 23, 2018 · 2 revisions

You will have to first install Project Lombok for your IDE

Follow the steps mentioned on this page if your IDE is Eclipse, else checkout their install page for other IDEs. They have support for various Eclipse offshoots in addition to Intellij IDEA, Netbeans and Visual Studio Code.

We use lombok in our code base for two main reasons:

1. @Data - To eliminate writing boilerplate code for our classes.

We do this by using the @Data annotation available to us through the lombok library. First we need to import the mentioned annotation. This is done by adding the line import lombok.Data to your import list of your class. After this annotate your class with @Data. Example. And just like this you can now take advantage of the @Data annotation. The advantages have been mentioned below and have been quoted directly from here.

@Data generates all the boilerplate that is normally associated with simple POJOs (Plain Old Java Objects) and beans: getters for all fields, setters for all non-final fields, and appropriate toString, equals and hashCode implementations that involve the fields of the class, and a constructor that initializes all final fields, as well as all non-final fields with no initializer that have been marked with @NonNull, in order to ensure the field is never null.

@Data is like having implicit @Getter, @Setter, @ToString, @EqualsAndHashCode and @RequiredArgsConstructor annotations on the class (except that no constructor will be generated if any explicitly written constructors already exist).

2. Help maintaining a log file.

References:

@Data

Clone this wiki locally