How to get rid of getter, setter in Java

One of the boring stuff to do in programming is to add getter, setter methods. Thanks to IDEs nowadays with few clicks or pressing shortcut keys you are able to add getters and setters to code. However, still much of coding space is wasted and besides that from my point of view readability of code is reduced. This is more severe when some developers tend to add business logic within getters, setters which is strongly discouraged in most of programming books. Hence, the best approach is to get rid of getters and setters.

In Java there is a useful library called Lombok which injects getters, setters using JPA annotation. This is particularly useful as it saves much of space, but more importantly, it stops developers from adding business logic in getters and setters. Besides adding getters, setters many other useful methods (such as toString, hashCode, equals, etc.) are also injected to classes that reduces need of coding.

To get more information on Lombok have a look at its website at this link,

Leave a Reply