Records Are Here! Can We Remove Lombok Already?

Emanuel Trandafir
CodeX
Published in
4 min readNov 13, 2022

--

In this article, we’ll discuss Java 17’s records and see if we can leverage the new keyword to completely replace the usage of Lombok.

image generated on imgflip.com

1. Records vs Lombok’s @Value

Lombok offers the @Value annotation to help us generate immutable “value objects”. Even though this can come in handy in some situations, I rarely saw this feature used.

For instance, the following code snippet will generate an immutable FullName class:

Though, we can further simplify this declaration by using Java 17’s new feature, the record keyword:

The two solutions will have the same result. In this case, it will be simpler to use the language feature rather than some external library.

image generated on imgflip.com

--

--

Emanuel Trandafir
CodeX

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