Member-only story

Lombok A library for getting rid of getter setter for your Pojo.

krishankant singhal
2 min readJan 6, 2021

--

Recently i got a chance to work on microservices ,In existing code i observed some annotations in my pojo or JPA entities and did not see any setter or getter for properties defined. But in my whole code getter and setter were getting used .I realized there is something going behind the scene and these annotation are generating setter getter for my JPA during compilation time. After some research i had an answer. answer was a library known as lombok :)

Getters/Setters, Constructors — So Repetitive

Encapsulating object properties via public getter and setter methods is such a common practice in the Java world, and lots of frameworks rely on this “Java Bean” pattern extensively: a class with an empty constructor and get/set methods for “properties”.

This is so common that most IDE’s support autogenerating code for these patterns (and more). This code however needs to live in your sources and also be maintained when, say, a new property is added or a field renamed.

Below is an User entity , without lombok we have to write setter and getter and no argument constructor for the same , which will increase the code size and unnecessary code.

@Entity 
public class User implements Serializable {
private @Id Long id; // will be set when persisting
private String firstName;
private String lastName;
private int age;
public User() { }…

--

--

krishankant singhal
krishankant singhal

Written by krishankant singhal

Angular,Vuejs,Android,Java,Git developer. i am nerd who want to learn new technologies, goes in depth.

No responses yet