๐ช๐ต๐ฎ๐ ๐ถ๐ ๐ถ๐?
Lombok is a Java library which auto generates boilerplate code through the use of annotations.
It can generate code for getters/setters, ๐๐๐๐๐๐(), ๐๐๐๐๐ฒ๐๐๐(), ๐๐๐๐๐๐๐๐() and even constructors/builders.
๐ช๐ต๐ ๐๐๐ฒ ๐ถ๐?
It eliminates boilerplate code which leads to…
- Improve readability since there is less clutter and also makes pull requests easier to review.
- Increased productivity and frees up your time to focus on core business logic.
An example
No Lombok:
| |
With Lombok:
| |
- All the boilerplate code is replaced with just a
@Dataannotation. - If you need to add new attributes, you don’t need to change the
equals(),hashCode()andtoString()methods as Lombok will handle them for you!
How to get started?
Note:
The setup below is for maven projects.
At the time of writing, the latest of Lombok is 1.18.38.
Add the Lombok dependency in your pom.xml:
| |
After adding the Lombok dependency, you might get a prompt from your IDE to enable annotation processing (If you don’t get the prompt, you will have to follow your IDE specific instructions to enable). Enable annotation processing.
Add the following plugin in your pom.xml so that maven build can use the Lombok generated code.
| |