Lombok & LambdaJ

Working with Java has been almost inevitable for me. Many clients who have their projects written in Java and in the near future not going in for any rewrite will stick with them. Several Java frameworks and libraries have made heavy lifting simple and made software development more predictable and easy to code.

Some frameworks mandate the use of getters and setters to work with Java beans which make the code look bloated. It was also pointless to get these getters and setters covered in tests and they end up showing as uncovered. We have to configure to avoid these methods from showing up in the coverage metrics. Also the presence of getters tempts a developer to make use of it as a backdoor and get some quick fix done.

Lombok came to the rescue, with simple annotations it inserts the necessary getters, setters, constructors, equals, hashcode. These methods are added at the compile time which make the code look clean on the editor. Eclipse and Idea have plugins to support injected methods (Though it would be great if we do not rely on hand written code to make use of these generated methods. We should leave them only for the consumption of frameworks or libraries which demand getters and setters).

The other problem I routinely faced was the frequency at which we handle and manipulate collections. LambdaJ provides a pseudo functional way to work with collections. It makes the code very terse and when used in combination with Lombok on domain objects, Java code looks super neat with few hand written necessary methods while all the boiler plating is left to the compiler.

Lombok and LamdbaJ together will make working with Java code more coder friendly.

1 Comment

  1. Wow glanced at your post as we’re using lambdaj and it’s one of the coolest things I’ve come across. Hadn’t heard of Lombok before though, but it’s blown my mind. Boilerplate code been bothering me for a while and the elegance in which Lombok gets rid of it is amazing! Thanks!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s