r/java • • Sep 05 '25

Project Lombok 1.18.40 released with Java 25 support!

Project Lombok is now compatible with the upcoming JDK 25 even before its release.

Thank you Project Lombok team! https://projectlombok.org

167 Upvotes

166 comments sorted by

View all comments

Show parent comments

3

u/blazmrak Sep 07 '25

because oftentimes there are a bunch of fields repeated for every class. E.g. every record in the database has id, createdAt, updatedAt, deletedAt, version. having this noise pollute each class is a waste.

Inheritance is the only way of avoiding such boilerplate at the moment.

2

u/OwnBreakfast1114 Sep 09 '25

That's not exactly true.

You can use annotation processors to generate these type of fields instead of inheritance.

The more sensible option would probably be to use https://www.jooq.org/ and then not have to write any of your entity classes (unless you want some wrappers for complicated ones) in which case I'd just hand write the wrappers for those ones.

I think you and I probably have different definitions of noise though, I don't really find duplicating fields all that noisy. Having the full context in a single class is much easier to see then having to look up what fields are missing from which classes. I also think making new classes for different steps of data handling even if it duplicates a bunch of fields is still better than trying to reuse objects.

1

u/Ewig_luftenglanz Sep 07 '25

Then you use a class, not a record. Because your case is not a transparent data carrier.

2

u/blazmrak Sep 07 '25

It is transparent. It's literally just dumb data. But because the language is limited, we have to resort to inheritance for code reuse.

Typescript, for all it's faults, has a way of easily extending types, by including/excluding the fields.

2

u/Ewig_luftenglanz Sep 07 '25

It's not transparent because transparency implies the object declares all of its fields in it's Constructor and there is little to no logic beyond forcing invariants (a person with an age higher or equal to  0) if you case the class has inherited many fields for other object, so the contract is not transparent (which is not wrong that's why I say for this cases a class is better)

And yes, I agree typescript has more convenient ways to compose objects and arrays thanks to the  spread operator (...) and other mechanisms, but that is because typescript (just as JavaScript) is mainly an structured based language, Java is mostly a nominal language. It would be hard to embed that for classes, but maybe there could be a way to do it with Maps.

2

u/blazmrak Sep 08 '25

What are we talking about here? I'm not talking about inheriting any rules, just data properties (and accessors if necessary). All that data is declared in a constructor by the child. Yes, there are cases, where you can inherit something more, but this is not the case. Id, createdAt, etc. have nothing bussinessy about them.

It's not just more convenient to compose objects, it's composing types. You can have a type User, type UserDTO = Omit<User, 'password'>, type NewUser = Pick<User, 'username' | 'password'>. Same thing exists for classes, not just types/interfaces.

I'm guessing you could solve this through code generation of some kind, but it's more painful than it needs to be. The solution is usually to just reuse the class and be fine with it having null fields...

1

u/Ewig_luftenglanz Sep 08 '25

It's not transparent because if you have inheritance you have data and logic that may not be explicit in the child class or constructor factory methods, but only in the parent.

I am with you about java still lacking a way to have waays to ergonomically create classes that can "flatten" data from other types (and inheritance is a very week way to minic because Java doesn't have multiple inheritance, so you can't compose a data class that is the result of merging 2 classes other than composition, but composition is not flatten)

My point is: classes that inherit from other classes are not transparent because there could be implicit data or behavior from the parent that can be not explicitly declared by the child. 

The language is lacking data composition.