What is Project Lombok?
Project Lombok is a java library which can be included in your java project and you will never have to write/generate boring getter/setter/equals etc. methods in your java class.
Lombok can be easily integrated with your IDE like Eclipse or IntelliJ Idea. Once integrated you will be able to use the methods generated from Lombok directly in your classes without writing them explicitly.
Lombok will add the specified methods via annotation during build time so that the methods are part of your class file.
Using Lombok greatly reduces the lines of code which will in-turn increase the code quality and leads to easier maintenance.
Few of the most important annotations in Lombok are:
- @Getter/@Setter - Which will generate getter/setter methods.
- @ToString - Generates a toString method with the declared variables.
- @EqualsAndHashCode - Generates equals and hashCode method.
- @Data - Combination of @ToString, @Getter, @Setter, @EqualsAndHashCode and @RequiredArgsConstructor.
To use lombok in your maven project you just need to add the below dependency in your pom.xml
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.4</version>
<scope>provided</scope>
</dependency>
</dependencies>
How to integrate Project Lombok to your IDE?
Eclipse:
IntelliJ Idea :
No comments:
Post a Comment