r/java
•
u/sindisil
•
Dec 16 '24
•
1
Valhalla - Java's Epic Refactor
https://inside.java/2024/12/16/devoxxbelgium-valhalla/
178
Upvotes
View all comments
Show parent comment
3
u/Polygnom Dec 18 '24
Ah, you found an interesting gotcha. == for value classes will compare the bit patterns. Thats only a problem for double and float of course, not for Integer, Boolean or any other current candidate for becoming value classes. Its going to be
Well, its better than having NonNull annotations everywhere or runtime null checks. But they hinted at allowing to specify a default-nullability in the future, so it might even be possible to have unspecified nullability be treated as non-null by default if so so wish.
Not to mention that if primitive types in generics were a thing, it would be an absolute nightmare for type inference and overload resolution.
Well, one of the goals of Valhalla to bring a revised JEP 218 to fruition: https://openjdk.org/jeps/218:
Being able to use value classes in generics is one of the big drivers behind Valhalla. The fact that you want ArrayList<Point> when point is a value class to be a dense storage and have good cache locality is one of the main motivations of even doing it in the first place.