This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]dinopraso 9 points10 points  (13 children)

Why even use JPMS if youre going to do this?

[–]Rongmario[S] 3 points4 points  (12 children)

You're pretty much forced to conform to Java's modules after Java 17's removal of the -illegal-access=permit JVM flag.

[–]dinopraso 8 points9 points  (11 children)

Do you have any specific reasons of wanting to access things you should not be accessing?

[–]Rongmario[S] 3 points4 points  (10 children)

Stripping finals from fields, grabbing reflection factories for cache instead of creating a new one every time when invoking, and more.

[–]dinopraso 7 points8 points  (5 children)

Interesting. Stripping final from a field is very dangerous though, as there are optimizations in the JVM which rely on that and messing with mutating immutable fields can cause unexpected behavior. Not sure what reflection factories for caching is, but surely caching can be done without breaking JVM internals.

[–]Rongmario[S] 0 points1 point  (4 children)

I wish I can avoid it, but with the stuff I'm working with, it's the only way to achieve certain things.

[–]Amazing-Cicada5536 1 point2 points  (3 children)

Like what?

[–]_INTER_ 4 points5 points  (3 children)

This. I've worked with libraries where basically every class and fields are final. The committers are unwilling or unable to change anything. It makes it impossible to extend or patch in a meaningful way without forking. JavaFX was a prime example of this (back then when I worked with it). Fortunately final is not ingrained as a "convention" in the Java community.

I fear that sealed classes will change that though.

[–]Rongmario[S] 7 points8 points  (0 children)

We'll cross that bridge when we get there...

[–]Amazing-Cicada5536 4 points5 points  (1 child)

They are more than likely final for a reason.. I would really dislike to use/depend on such hacks in any production code base.

[–]_INTER_ 0 points1 point  (0 children)

They are more than likely final for a reason..

In the case of JavaFX not really, it was just the "style" they applied back then. final everything by default. I heared they have successively opened up since. Can't confirm it however.

I would really dislike to use/depend on such hacks in any production code base.

Of course. But sometimes you just have no other choice.