Java & Lombok, a tale of two islands
This is the first in a two-part series on spicing up Java with Lombok.
Java has been with us for more than 25 years. In 2020, it is still relevant and a great language to have under your belt as a programmer. As beautiful as it is though, there is also a lot of criticism.
Especially, Java is considered to be quite verbose. Why do we have to write getters and setters? And what’s up with equals() and hashCode() anyway?
This is where project Lombok comes in.
Lombok is a neat little library that leverages annotations to generate Java boiler plate code. From simple getters and setters to full fledged builders, it really is a swiss army knife for the Java developer.
To use Lombok, we have to add it to our project first. In Maven, we add it as a dependency to our pom:
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.16</version>
<scope>provided</scope>
</dependency>
Because Lombok is only needed in the generate-sources
phase of our build cycle and we don’t need it in production, its scope should be provided
.
Annotation processing
Lombok uses annotation processing to generate code. Our IDE has to be aware of…