r/java • • Jul 16 '26

Identifying JDK value class candidates

https://mail.openjdk.org/archives/list/core-libs-dev@openjdk.org/thread/Y72NRXM7KYBX43OKYBQMVKOZDWKG4MHS/
52 Upvotes

59 comments sorted by

View all comments

Show parent comment

6

u/Jon_Finn Jul 16 '26

Aside from the obvious use cases, I see a major unsung benefit in allowing you to create classes wrapping a single int, double etc., when currently the performance downsides make it not worth it in certain applications. I mean things like units, ages, numbers with particular ranges/constraints, unicode code points (21 bits) etc. - where some might 'want' a typedef with methods. Nullability and specialised generics will be a big help here. My point is: these classes currently don't exist in my code, but now could.

5

u/pron98 Jul 16 '26

I see a major unsung benefit in allowing you to create classes wrapping a single int, double etc., when currently the performance downsides make it not worth it in certain applications

That is true, but I think that generally speaking, many "performance issues" in Java are imagined and/or based on folklore that may have been true in, say, Java 8.

My point is: these classes currently don't exist in my code, but now could.

I agree, but I would also add that you might well have them today with no performance impact. We must be careful to not assume a performance issue that doesn't actually appear in our concrete program's profile.

3

u/Jon_Finn Jul 16 '26

Sure, though the cases that I'm particularly thinking of involve large (sometimes huge) arrays of very small objects, where these simple intuitions are (probably!) correct for once.

2

u/pron98 Jul 16 '26

Right, so that's exactly where Valhalla could have a significant impact.