When to Use Lombok?

When to Use Lombok?

Lombok is used to reduce boilerplate code for model/data objects, e.g., it can generate getters and setters for those object automatically by using Lombok annotations. The easiest way is to use the @Data annotation.

Why you should not use Lombok?

The reasons for not using this annotation are very similar to the case of @Builder : it allows object creation in invalid state. And how else can you add values to this class if not using the also discussed @Setter ? Use it only if it makes sense to your object that it exists with all empty values.

What is the use of Lombok in Java?

Project Lombok is a small library that can be used to reduce the amount of boilerplate Java code that is commonly written for Java classes. Project Lombok does this via annotations that can be added to the Java class for which common methods are desired.

Sarah Jenkins
Author

Sarah Jenkins

Sarah Jenkins is a veteran tech journalist with over 12 years of experience covering artificial intelligence, mobile innovations, and digital ethics. Her insights have appeared in leading technology publications worldwide.