Do you feel lazy every time you declared the Java Bean with Getter and Setter method? Do you feel boring when working with boilerplate code in Java? If all answers are yes, let’s consider using Project Lombok. It can help you avoid these problems.
So, what is Project Lombok?
Project Lombok is a tool that can generate code for us, but not in the way the IDEs did. Our IDEs generate Getter, Setter, Equals and more methods then put them into the .java file. Project Lombok does the same thing but does it in .class file. All we need to do, that is, add some annotations like @Getter, @Setter, @Builder,… into our code and Project Lombok will generate Getter, Setter and so on for us. You can override the thing you don’t need to generate it automatically.
Because Project Lombok generates code at compile time into .class file, so, to make our IDEs can understand the code at writing time, we must add Lombok plugin into our IDEs.
Let’s take some basic examples about Project Lombok:
In this tutorial, I will show you some instructions on how to deal with Getter, Setter and constructors with Project Lombok.
In this tutorial, I will show you how to generate toString(), equals() and hashCode() method automatically with Project Lombok.
Using @Data annotation in Project Lombok, you can avoid declaring Getter, Setter, toString(), equals() and hashCode() method.
In this tutorial, by using @Builder annotation, we can apply Builder Pattern for our objects.
In this tutorial, I will show you how to generate Logger objects automatically with Project Lombok.
In this tutorial, I will show you another way to close a resource automatically with Project Lombok.
In this tutorial, I will show you an alternative way to use synchronized keyword in Java with Project Lombok.