The power of Lombok


Today I would like to introduce you to Lombok – a very useful tool for Java coders.

What is Lombok?

Shortly speaking, it’s a library that reduces the amount of boilerplate code in your Java projects. Let me show you some Lombok power using example with simple Employee class. Employee has three fields along with corresponding getters/setters.

public class Employee { 

private String name; 
private String surname; 
private int age; 

public String getName() { return name; } 
public void setName(String name) { = name; } 
public String getSurname() { return surname; } 
public void setSurname(String surname) { this.surname = surname; } 
public int getAge() { return age; } 
public void setAge(int age) { this.age = age; } 

Now see what happens when you are using Lombok:

import lombok.Getter;
import lombok.Setter;

public class EmployeeWithLombok {

private String name; 
private String surname; 
private int age; 

Yes, this code above is sufficient – you only need two Lombok annotations to have all your getters and setters available.

And I have once thought that have your getters/setters generated by Eclipse is a cool thing 😉

What else can Lombok do for you?

Generates your setters/getters:

Generates implementation of Object methods:

Generates your constructors in different variants:

Generates a builder for your objects:

You can find some more at Lombok site: 

And how to get it

Now I will show how to get Lombok running in your Eclipse:

  1. Go to and get newest lombok
  2. Go to Windows cmd and find directory where you download lombok.jar
  3. Type: java – jar lombok.jar. The Lombok window should appear:lombok_installing
  4. Click on Specify location..  and find directory with your Eclipse.inilombok_installing_find_eclipse_ini
  5. . Then click on Install/Update and have your Lombok installedlombok_installing_successfull
  6. . Restart yout Eclipse (if needed)
  7.  Add Lombok dependency to your Maven pom.xml
  8. Click on Project -> Maven -> Update Project
  9. Enjoy Lombok power! 🙂

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s