All the 16 Lombok Annotations Explained in a 4-minute article

Emanuel Trandafir
Javarevisited
Published in
5 min readFeb 2, 2023

--

Explaining each of the 16 annotations in less than 20 seconds. How many of them did you know?

Photo by Sabri Tuzcu on Unsplash

Lombok is a Java library that can generate known patterns of code for us, allowing us to reduce the boilerplate code. In this article, we’ll walk through each of the 16 annotations provided by Lombok and quickly discuss how to use them.

@NotNull

This annotation can be used to validate a constructor or a method parameter. Additionally, if we annotate a field with @NonNull, the validation will be added to the constructor and setter method. Let’s compare the plain-java solution with Lombok’s @NonNull:

@Getter & @Setter

Perhaps the most popular Lombok annotations, @Getter and @Setter can be used to automatically generate getters and setters for all the fields:

@ToString

--

--

Emanuel Trandafir
Javarevisited

Hi, I'm Emanuel Trandafir, a Java developer from Romania. I have a strong passion for clean code, software design, and unit testing.