r/java • • Jul 31 '26

JEP 401: Value Objects And JEP 539: Strict Field Initialization Merged Into JDK

https://github.com/openjdk/jdk/commit/cc278dbb8a1ca0754d5842708b9029441055d361
185 Upvotes

64 comments sorted by

View all comments

Show parent comment

2

u/grashalm01 Aug 02 '26

Module's are useless rn for library maintainers. Because even if you ship your library with a module descriptor people will put it on the class path and ignore your module descriptor as if it weren't there. And no don't expect your users to put your library on the module path because application developers couldn't care less about modules. Nobody wins currently, library devs get extra work with zero benefit.

The JDK does not have this problem because they can enforce module behavior for their libraries always.

1

u/ZimmiDeluxe Aug 02 '26

I would expect IDEs to warn against importing non-exported packages of dependencies, even if they are on the class path, but I haven't checked if that actually happens.

2

u/grashalm01 Aug 03 '26

My IDE doesn't do that. And I don't think it would be a strong enough guarantee.

1

u/ZimmiDeluxe Aug 03 '26

Thinking about it, that should be a javac warning, same as detectable split package shenanigans. It's not a very strong guarantee, but currently you only have the "internal" naming convention to communicate intent, a warning would be an improvement. I've imported internal Hibernate utils in the past by accident, it would have come in handy. Nudging the ecosystem toward modules might be a good idea anyway, at least once Maven 4 is released and building them is less of a hassle.

2

u/grashalm01 Aug 03 '26

I think it should be enforced on the JVM side. With an explicit opt out. I made concrete suggestions to the java team without any success.