Hacker News new | ask | show | jobs
by javanonymous 996 days ago
Lombok can be used for more than just getters/setters.

I personally use the @Builder annotation on records with more than 3-4 fields. I find it much more readable than a long list of arguments to the constructor.

It also makes it easy to return a copy of the record where only a few fields have changed:

   var r = book.toBuilder()         
           .lastUpdated(now)
           .title("...")
           .build()

I also use other annotations, but I could work without them if a future version of Java provides a builder-like pattern (or named arguments)
2 comments

Totally, and the With annotation is a bliss. Hope to have it at a syntax level someday, just like in Kotlin. In addition, you can decompile Lombok annotations straight into your code proper and change what you need, Builder methods for validation, say. Lombok is great for DX, especially if you have experience with more recent languages.