What is Project Lombok
Project Lombok is a popular Java library that is used for reducing boilerplate code in Java applications and increasing developer productivity.
This boiler plate code includes:
1. Getter and Setter methods of class fields or instance variables.
2. Constructors.
3. toString()
method.
4. Overriding equals() and hashCode() methods.
5. Calling close()
on database connection or file streams.
6. Using synchronized keyword to make methods thread safe.
7. Creating logger objects(log4j, Slf4j) for logging.
8. Adding builder pattern support to create class objects.
With lombok, you can add all these using annotations. Yes, you read that right !!.
If lombok is added to your project, there is no need to manually create getter/setter methods, constructors and all those listed above.
These will be automatically taken care of by lombok library.
Lombok documentation states
Project Lombok is a java library that automatically plugs into your editor and build tools, spicing up your java.
Never write another getter or equals method again, with one annotation your class has a fully featured builder, Automate your logging variables, and much more.
The library’s name, “Lombok,” is a combination of “Less” and “Boilerplate,” indicating its primary purpose of decreasing the amount of repetitive code that developers frequently have to write.
In this easy to understand lombok tutorial, you will learn everything right from setting up lombok in your projects to using its features with examples.
Before moving further, first let’s install lombok in your favorite IDE and project.