Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Lombok is an opensource project that reduces boiler plate code in the Java Pojo's by using annotations in the class. The main advantage of Lombok is to get rid of generating getters & setters (although the IDE generates it).

The source code can be found in GitHub.

Lombok in Action:

Add the dependency in pom.xml

Code Block
languagexml
themeEclipse
titlelombok maven
<dependency>
   <groupId>org.projectlombok</groupId>
   <artifactId>lombok</artifactId>
   <version>1.18.2</version>
   <scope>provided</scope>
</dependency>
Code Block
languagejava
themeEclipse
titlelombok example
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class Book {
	
	private int id;
	private String name;
	private String author;
	
}

Other useful Annotations:

@ToString

@Builder

@NoArgsConstructor

@RequiredArgsConstructor

@EqualsAndHashCode and lot more ..


IDE's like Eclipse & IntelliJ does not detect the lombok annotations by default.

Lombok in IntelliJ:

Go to File → Settings → Plugins → Browse Repositories. Search for lombok.

Lombok in Eclipse:

Download Lombok and run the Jar. Specify the eclipse location and click Install.

Image Added

Check the eclipse installation of lombok in About eclipse.

Image Added


Other useful Reference:

How Lombok Works

Lombok Features