Project Lombok — the most undervalued java library

Back in 2010 a colleague of mine mentioned about a open source project called lombok. I ignored his advice as, I am no different from the people who judge the websites based on fonts and appearance. This website is probably built with the same philosophy of providing aesthetic appeal to the brand in itself. A few likes are reddit, craigslist and more notably berkshirehatheway.com the company with assets more than $5oo billion. Would anyone not invest in the company just because of this website? the answer is NO. Likewise let us not bogged down by the appearance of website and leverage, what is it to offer.

I am sure 90% of people who visit a website that has a home page shown below shall have a strong opinion about it’s naivety and lack of sophistication.

A good developer always strive to write super good high quality code whilst try to avoid repetitive menial coding tasks. Project lombok shall help you in some degrees on both the aspects.

But trust me this IDE plugin eliminates the need of writing common boilerplate code in Java by using just simple annotations.

@Getter and @Setter

Adding simple annotation on the class variable will generate the getter and setter method for the variable at the compile time. Most importantly if the variable is of type boolean the code generator shall automatically use “is” as a prefix for the getter method. Manually implementing a getter or setter within the class will automatically override the behavior of the Lombok annotation, which can be useful when the annotations have been placed at the class level.

@Cleanup — No more try, catch finally

This annotation is provided for automatic resource management. Calling stream’s close() methods becomes easier without writing try, catch and finally every time.

@NonNull — No more NullPointerException

It is similar to the @NonNull of Java 8, but an important feature of lombok thats is more often used . Use this to stop worrying about the NullPointerException, often thrown by third party libraries.

Is there more?

There are a few more @Data, @ToString, @EqualsAndHashcode, @AllArgsConstrutor and @Synchronized. All of them are really useful to a certain degree if you want save your time.

Don't like it?

It is simple, if you don’t like it or you want to take control over the generated code for some reasons, No problems they provide a tool called delombok and the instructions are here

Warning

If you are an Android developer, you need to be aware of some limitations. Also avoid packaging lombok into the dex .

Add the below line in your build.gradle
provided “org.projectlombok:lombok:1.16.+”

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.