I’ve recently discovered an interesting java project, Lombok, that gives your IDE the ability to automatically create trivial methods (setters and getters, hashCode, equals, toString, and basic constructors) and other stuff.
All you need to do is watch the 3-minutes video at Project Lombok web site, download the little jar, click 2 buttons to install it, and then start annotating with Lombok.

I’m using Lombok in Eclipse, in project with the latest Spring libraries (currently the 4.3 series). For now, the annotations that I use the most are @Data and the ones it depends on. The integration and the outcome are very fine!

I will give the project few adjectives, to explain why I’m liking it very much.

Simple – Less than 20 annotations are not hard to learn.

Clear – The annotation names are quite easy to read amidst your source code (and to remember).

Fucused – The project aims few and clear targets (for example, you don’t need all the dependencies of SpringRoo only to just automate setter and getter creation).

Light – My Eclipse doesn’t slow down for this addiction.

Flexible – The annotations have various attributes to change their behaviour.

Two examples for the last point.

@EqualsAndHashCode has a boolean switch called callSuper, that defaults to false. If you adds this annotation to a derived class without that attribute, the IDE shows a warning saying that you are relying on the default.

You can customize the generated setter methods. For example, the following line adds Spring’s @Required as method annotation:
@Setter(onMethod = @__({ @Required })). A little bit odd but I can cope with that.

And as a bonus the documentation is spiced with references from movies I like.

However, I strongly suggest to read the article Reducing Boilerplate Code with Project Lombok before adopt Lombok in your projects.

Annunci