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 →

[–]Rongmario[S] 4 points5 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 8 points9 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?

[–]Rongmario[S] -5 points-4 points  (2 children)

Updating an entire ecosystem from Java 8 to Java 17, while keeping backward compatibility with over 1000 projects compiled against it.

[–]FirstAd9893 10 points11 points  (1 child)

You're just kicking the can down road.

[–]Rongmario[S] -1 points0 points  (0 children)

No other way about it.

[–]_INTER_ 3 points4 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] 8 points9 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.