Renato Ivancic - Software Engineer

Background image

Lombok, boilerplate eliminator


Lombok Logo


Project Lombok is a java library that automatically plugs into your editor and build tools, spicing up your java. It will alow you to get around the java language verbosity. It is generating byte code in the compilation process, that said it is only a build time dependency. At a runtime we don’t need it anymore. For this reason we can develop libraries with the help of lombok and library users won’t be dependend on it.

UtilityClass annotation

In the documentation its written “All members of a utility class are automatically marked as static. Even fields and inner classes.” But this is actually not the case with version 1.16.18. Git Lombok issue

EqualsAndHashCode exclusion

I can remember the cases where id or for example quantity field doesn’t define the equality of an entity. Maybe for your business logic it doesn’t matter if smartphone was manufactured on 13 of Friday or 24 of December, the distinction will be done by the brand, type and so on. To exclude members from equals and hashCode methods in lombok version prior you can pass the list to the @EqualsAndHashCode annotation.

@EqualsAndHashCode(exclude = {"xMember", "yMember","..."})

on the other hand you can explicitly specify in annotation which fields must be included.

@EqualsAndHashCode(of = {"xMember", "yMember","..."})

Eclipse Lombok and MapStruct

Project setup from the FAQ page of MapStruct.

When MapStruct is used with Lombok annotation processor inside of Eclipse, MapStruct annotations are not processed successfully. Be sure to use patched Lombok jar for the Eclipse IDE. Maven and IntelliJ compilation is working without issues.

Patched Lombok version provided: MapStruct github page



#Java #Lombok