JavaPythonTech blog contains various tools and skills for a developer. Java/Python Best Practices, Tools, Examples, Programming interview questions.

What is Project Lombok and why you should use it?

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:

  1. @Getter/@Setter - Which will generate getter/setter methods.
  2. @ToString - Generates a toString method with the declared variables.
  3. @EqualsAndHashCode - Generates equals and hashCode method.
  4. @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 :


Share:

No comments:

Post a Comment

Announcements

Will be posting twice a week on latest java libraries/frameworks which a developer needs to know in 2019.
Also will add the common errors and resolutions for the same.

Please feel free to comment if you need anything specific.

Recent Posts

Popular Posts

Search This Blog

Blog Archive

Powered by Blogger.

Contributors

Pages