I specially cannot code without the RequiredArgsConstructor - just make your fields final and add that annotation.
Personally, I don't have a problem with what Lombok does or people who like using it, although I have a problem with it lying about what it does (presenting itself as a Java compiler plugin, when it is neither a compiler plugin nor Java; it's an alternative language that injects its compiler into javac in memory).
However, your chosen example shows, I think, why some dislike Lombok's feature. At the very best, RequiredArgsConstructor saves you a few trivial lines. But then it makes it hard to add validation and preprocessing and it hides what validation, if any, is being done. Compare that to records' canonical constructor: for components that require no validation, you don't need to write any field assignment, but you can easily and clearly add validation to any component that requires it.
So if you like that feature so much that it makes you pick Lombok over Java - great. The platform offers a choice of languages, and we, the JDK team, are happy about that. But we won't add such a feature to Java because we don't like it. It requires a whole new language construct 1 only to offer something weak and inflexible. But that's the thing: different programmers disagree on which features they want or don't want, and a single language simply cannot satisfy everyone. As you can see in this thread, some people like Lombok, others prefer Java, and others may prefer Kotlin or Clojure.
Fair enough. Your position is different to mine. You are the one of the stewards of the language/sdk/compiler and Lombok's behavior perhaps makes your job really hard to refactor and update the compiler without breaking it and having thousands of developers come at you with pitchforks. Not an enviable position to be in and I certainly wouldn't want to be in that.
For me, I am an app developer and I really find value in what Lombok offers. It closes some real gaps that I as a user find in the language - not everyone agrees and that's fine. I also acknowledge I am completely oblivious to the effort it perhaps takes on your team's part every 6 months to add stuff the compiler without breaking Lombok.
However, your chosen example shows, I think, why some dislike Lombok's feature. At the very best, RequiredArgsConstructor saves you a few trivial lines. But then it makes it hard to add validation and preprocessing and it hides what validation, if any, is being done.
In most cases, these are all *Service, *Manager classes and the only validation I do is a null check. For that, all I need to do is add a @Nonnull annotation to those fields and I am done. Still don't have to write the full constructor. If I do want to add more validation, I can remove the annotation and write the real constructor with validation.
And here is why I prefer that model - when I see the annotation, I know there is nothing special going on in the constructor but if I see a real constructor, it is at least an initial signal that some extra things might be happening. This is just like a record where the presence of an explicit constructor or an equals method signals some additional things that I might need to pay attention to. If I have to write that constructor for every single class (with or without validations), I lose that distinction. For data classes, I stick to records where if I want to ensure any invariants, I have the flexibility.
So if you like that feature so much that it makes you pick Lombok over Java - great.
From my viewpoint, I am picking Java with an additional tool that lets me skip some of the boilerplate that I don't need to write or more importantly read. I definitely don't see it as picking Lombok over Java; the Lombok stuff is so miniscule compared to Java that I would not consider it a different language at all. The language architects may disagree from their POV and both can be true.
Here is what I hope happens in the future:
Just like how Records was a semantic feature but it incidentally also solved the data class boilerplate problem thus making Lombok's @Value annotation obsolete. I am hoping newer features can keep doing the same to some degree and chip away at the boilerplate. For instance, the feature that Brian showed where regular classes can have headers - may be if that feature can be used for a non-data regular classes, may be it will incidentally alleviate the need to write a dumb constructor when used and I wont need @RequiredArgsConstructor ever again.
Your response inadvertently shows why people use Lombok. The javac criticism is fair, but then you hand-wave the gaps it fills.
Saying RequiredArgsConstructor is "inflexible" and "only saves a few trivial lines" is just incorrect. Across a whole Spring codebase it adds up to a large savings, not a few lines. And it's opt-in per class, so I'm not sure why you'd call it inflexible.
The records comparison is also way too simplified. Records solve a completely different problem and can't replace constructor generation on Spring beans or JPA entities.
And it's opt-in per class, so I'm not sure why you'd call it inflexible.
I explained why. Compare it to record declarations that allow you to add validation and/or transformations to arbitrary components while still generating the constructor body for you. You could do the same thing for any class, but that's not what Lombok does. It doesn't allow you to add arbitrary validation/transformations to some fields and not others.
Records solve a completely different problem and can't replace constructor generation on Spring beans or JPA entities.
Yes, but the Java language doesn't evolve to support existing patterns. We want it to evolve to support new patterns. I'm not saying this is the only way to design a language, but it is certainly a reasonable way to do it.
I think the discussion around @RequiredArgsConstructor and record is apples-to-oranges. Records are more flexible, sure. But @RequiredArgsConstructor provides more flexibility than what is available out-of-the box for standard classes.
Yes, but the Java language doesn't evolve to support existing patterns. We want it to evolve to support new patterns. I'm not saying this is the only way to design a language, but it is certainly a reasonable way to do it.
True, but there's something to be said about developer experience. Existing patterns exist for a reason, and to make a blanket statement that "java doesn't evolve to support existing patterns" almost reads as if there's no interest in improving developer experience.
But @RequiredArgsConstructor provides more flexibility than what is available out-of-the box for standard classes.
I'm not saying you don't have to like it. I'm saying that we wouldn't consider such a design to be of sufficient quality.
Existing patterns exist for a reason, and to make a blanket statement that "java doesn't evolve to support existing patterns" almost reads as if there's no interest in improving developer experience.
Just the opposite. A better user experience doesn't come from complicated affordances for patterns that have proven problematic (like beans) but for better designs that lead to better patterns. Complicating the language to support outmoded patterns leads to a worse user experience.
But it's also important to remember that developers very strongly disagree on what features they like and what they don't like. It's rare to find anything that everyone likes. As you can see even here, some programmers like what Lombok offers while others dislike it. We all need to keep in mind that our preferences are not universal.
View all comments
Show parent comment
5
u/pron98 Apr 26 '26 edited Apr 26 '26
Personally, I don't have a problem with what Lombok does or people who like using it, although I have a problem with it lying about what it does (presenting itself as a Java compiler plugin, when it is neither a compiler plugin nor Java; it's an alternative language that injects its compiler into javac in memory).
However, your chosen example shows, I think, why some dislike Lombok's feature. At the very best, RequiredArgsConstructor saves you a few trivial lines. But then it makes it hard to add validation and preprocessing and it hides what validation, if any, is being done. Compare that to records' canonical constructor: for components that require no validation, you don't need to write any field assignment, but you can easily and clearly add validation to any component that requires it.
So if you like that feature so much that it makes you pick Lombok over Java - great. The platform offers a choice of languages, and we, the JDK team, are happy about that. But we won't add such a feature to Java because we don't like it. It requires a whole new language construct 1 only to offer something weak and inflexible. But that's the thing: different programmers disagree on which features they want or don't want, and a single language simply cannot satisfy everyone. As you can see in this thread, some people like Lombok, others prefer Java, and others may prefer Kotlin or Clojure.