public class something(String name, int age) {
...
} public class something(String name, int age) {
...
}Say you want a POJO with accessors, mutators along with equals and hashcode. Let it generate the methods by defining a class like:
@Data
public class something {
String name;
int age;
}
Lombok generates: public String getName() { ... }
public void setName(String name) { ... }
public int getAge() { ... }
public void setAge(int age) { ... }
public boolean equals(Something other) { ... }
public int hashcode() { ... }
public String toString() { ... }For lombok specifically, other languages have these types of features built in which of course people need to learn in order to use it.
I agree it isn't a perfect solution, but java is in dire need of boilerplate reduction features like this and lombok fills this need well.
https://projectlombok.org/features/val.html
I've been doing C# for while... soo nice to have this. Coming back to java was like "why am I repeating myself". They already did the diamond operator on the right hand side, this makes the left just as nice.
now let the flames begin!!!
Oh also found a use for SneakyThrows today... I'm bootstrapping a test server in my unit test, where all of the code and interfaces are designed for safety and no-crash... and this lets me short circuit right out of it when something bad happens, which in a test setup is what I want.
Getters and Setters are verbose, but usually model classes are contained in a single class anyway, and can be generated automatically with any IDE. I can glance at a typical bean and ignore the code bloat without any problem.
The real issue is that Lombok generated classes don't play well with the dozens of libraries that expect Java bean style methods for auto marshaling and serialization: json generators, commons bean utils, binding libs, etc.
The savings aren't worth the trouble.
You can argue against Lombok for other reasons but was wondering about this specific one.