I am really enjoy the feature of project lombok that get rid of boilerplate code. My senior suggest me that lombok seems to use reflection to reduce boilerplate code and I once heard that using of reflection effect performance. My question is are there any issues to use project lombok?
Perhaps the biggest disadvantage of using Project Lombok is that generated code does not show up in the javadocs. This means that you will not find those public getters and setters in the generated javadocs. However, with every problem, there is a solution (or a workaround).
Lombok is an awesome Java library. It helps to reduce the amount of 'infrastructural code'. You don't need to write constructors, getters, setters, and even builders anymore. All you have to do is to put the proper annotations and the plugin will generate everything for you.
Immutables, Kotlin, Spring, Jackson, and Java 8 are the most popular alternatives and competitors to Lombok.
So Lombok is a huge hack that will only compile using javac or eclipse's compiler. It's a great piece of software, but it's also hated by many for being such a non-standard hack.
Lombok is a great tool that makes your Java code concise and clean. However, there are a few things to consider when using it with JPA. In this article we’ll look at how the misuse of Lombok can hurt the performance of JPA applications or even crash them, and how to avoid that but still gain the benefits of using Lombok.
Perhaps the biggest disadvantage of using Project Lombok is that generated code does not show up in the javadocs. This means that you will not find those public getters and setters in the generated javadocs. However, with every problem, there is a solution (or a workaround).
Using Lombok in the right way can make your code cleaner and easier to read. Take for example this simple POJO written with Lombok. This class is an example of a simple object which is used to hold simple data. By using the @Data annotation, we automatically added getters and setters for all those fields.
This tool is called Delombok. Delomboking your code can be done either through the command line or via your IDE. However, as with any code generation or handling tool, it does not always produce the perfect result.
Lombok does not use reflection at runtime. It hooks into the compiler internals and adds code to classes at compile-time, which is then compiled normally.
@chrylis answer is correct, but be careful with objects graph (@Data
and @ToString
annotation) e.g.
@Data public class A { private B b; } @Data public class B { private A a; }
Lombok will create toString with infinite recursion inside. You should use something like @ToString(exclude = {"a"})
inside class B
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With