I tried to summarize various things about Lombok. It may be helpful when adopting it in a project.
What is Lombok? An open source library that simplifies Java-specific redundant code (boilerplate code). Just annotate, getter, setter, toString, equals, etc. "Code to be written over and over again" is automatically generated at compile time.
--Boilerplate code can be removed from the code. --Accessor methods do not remain out of date when renaming fields. --The logic in the accessor method is not buried. --It is easy to get an appropriate value in the test coverage.
--There is a risk of becoming a circular reference with @ToString
.
→ In that case, exclusion can be set with exclude.
Click here for details → StackOverflow when using Lombok-toString method
--When changing the field name, the reference destination of the accessor method cannot be changed.
→ It is necessary to take measures such as changing from the automatically generated Getter / Setter of the IDE with the refactoring function.
Eclipse: Download lombok.jar from the following site and execute it. https://projectlombok.org/download.html Specify the same directory as eclipse.exe in Specify Location and install / update.
NetBeans:
Below, how to write Maven.
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.12</version>
<scope>provided</scope>
</dependency>
Due to the nature of Lombok, it is possible to completely change the coding feeling so far. It's a good idea to use coding conventions when using it in your project. The annotations and classes that can be used are described below.
val list = new ArrayList \
@Getter, @Setter, @ToString, @EqualsAndHashCode, @Data, @Value
@NoArgsConstructor, @RequiredArgsConstructor, @AllArgsConstructor
@Builder, @Singular, @NonNull, @Wither, @CleanUp
@Synchronized, @Log4j2, @SneakyThrows
Under the lombok.experimental package → There are many experimental functions, and there is a high possibility that specifications will change in the future. Example) Accessors (fluent = true), UtilityClass, etc.
Lombok usage memo Why it is better to use lombok than IDE accessor generation in Java