3 ms·
That was my reaction the first time I was introduced to it. I looked at it again two years later and it just clicked. What's really cool is that the developer
by smoyer 10y ago
That was my reaction the first time I was introduced to it. I looked at it again two years later and it just clicked. What's really cool is that the developer who has to go maintain it has 20% as much code to maintain.
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() { ... }
- marktangotango 10y agoThe real win is when you do Effective Java chapter 1 immutable objects with @Builder. I worked at a Big Dumb corp that eschewed lombok, and required full test coverage of getter, setters, builders, toString, equals, and hash mehtods, and 100% javadoc coverage for all methods (even private methods). It was insanity, and carpal tunnel inducing. Lombok would have reduced the workload by 90%.
- smoyer 10y agoYes! ... And there are a lot of stages between a fully immutable object @Value and @Data (described above). The @Builder is so much better than most but you can also easily create a POJO with a portion of its fields immutable too (a combination of @NonNull, @Getter, @Setter and @RequiredArgsConstructor).
- markelliot 10y agoIt might be worth a look at Immutables (http://immutables.github.io/ http://immutables.github.io/) or FreeBuilder (https://github.com/google/FreeBuilder https://github.com/google/FreeBuilder), both of which also use Java's built-in annotation processors to do code generation, but involve slightly less magic and produce generated classes which are not overwriting the original class.
- cs02rm0 10y agoOne of the nice aspects of it is that if you have, say, a setter method which does something slightly unusual (e.g. setLastName does a call to setName(getFirstName() + " " +lastName) - unlikely example perhaps) then it stands out from the crowd of otherwise straightforward getters and setters.
- skoczymroczny 10y agoBut then you switch to JavaFX and you realize Lombok won't help you with JavaFX properties generation :(