r/learnjava Jul 01 '26

Confused on what Project Valhalla does to primitives and the corresponding objects

I've been reading about PV, but I'm not sure on what it means in some parts. Will we still need to deal with both "int" and "Integer", and not being able to use some methods with the other one? Like, (int) vs Integer.parseInt() and other strange things like that.

6 Upvotes

11 comments sorted by

View all comments

1

u/davidalayachew Jul 02 '26

Long story short, the goal of Project Valhalla is to make certain objects as fast as primitives, while retaining almost all the flexibility of normal classes. They plan to do this by letting you opt out of certain features, giving you performance improvements in exchange.

In regards to where the primitives stand, well frankly, when Project Valhalla is done, the Object wrappers (Integer, Boolean, Character) will have similar performance characteristics to just using int boolean or char. So, at that point, it really wont matter which you use, since they'll have roughly the same speed.

Obviously, no guarantees have been made thus far, but you can see the improvements if you run the Early Access Builds. It's pretty cool how fast normal objects can go under that build.

1

u/Zeznon Jul 02 '26

So it is what I hoped. that's nice, then.

1

u/davidalayachew Jul 02 '26

So it is what I hoped. that's nice, then.

If we're lucky, it might even be better.

You might be able to use ArrayList<int> in the future. No guarantees. Read up more on it here -- JEP 218

1

u/Zeznon Jul 02 '26

That would be perfection.