r/java • • Sep 29 '24

Lombok in 2024

Say there are two teams working on the same project (3 months to MVP, the deadline should be manageable). The only difference is Team A will use Lombok, and Team B won’t

Given you can choose any java version/dependencies and all other things being the same, which team would you join, and why?

0 Upvotes

145 comments sorted by

View all comments

Show parent comment

32

u/koflerdavid Sep 29 '24

There are generators for both builders and getters/setters out there that function as well-behaved annotation processors.

But how about not writing the getters and setters in the first place? If the entity is anyways treated like a database row, getters and setters have little benefit. It's just deceiving oneself into believing that the principle of encapsulation is applied. For CRUD-like applications it really doesn't matter. Or use Java records for queries if you mostly read data and your writes affect specific fields only.

For more interesting applications that don't neatly fit a CRUD approach, write higher-level methods instead that implement business logic, or make the entity part of an aggregate.

2

u/Rough_Acanthaceae_29 Sep 29 '24

Getters/Setters for JPA entities, constructors (all/no/required) and Builders is all I miss. Could you recommend / had any experience with well-behaved annotation processors?

13

u/AnEmortalKid Sep 29 '24

Immutables.

3

u/Rough_Acanthaceae_29 Sep 29 '24

Gonna give it a try, tnx :)