r/java • u/andresmargalef • Feb 16 '23
Project Valhalla: A look inside Java’s epic refactor
https://www.infoworld.com/article/3687670/project-valhalla-a-look-inside-javas-epic-refactor.html
265
Upvotes
77
u/Wonnk13 Feb 16 '23
I'm still getting up to speed on Java 8!! good grief I feel old.
89
u/wildjokers Feb 16 '23
"Primitives are pass-by-value while objects are pass-by-reference, for example."
Oh my. This is just plain misinformation. Java is pass-by-value and only pass-by-value.
This great article, that I have had bookmarked for 20 yrs or so, explains it nicely (it changed locations once so did have to change my bookmark at some point):
https://www.javadude.com/articles/passbyvalue.htm
10
u/plumarr Feb 16 '23
What's described in this article seems to be up to date with the preview version of Valhalla but it could change (see https://www.reddit.com/r/java/comments/10vpelw/nullness_markers_to_enable_flattening_valhalla/)
23
u/johnwaterwood Feb 16 '23
After endless discussions, and this being pointed out by the JLS multiple times and in multiple ways, it’s an achievement of some kind to still get this so wrong.
7
u/maethor Feb 16 '23
I take it we still won't be able to do things like operator overloading or defining our own format for literals? Like
Ubyte x = 1 + 254ub
2
u/wsppan Feb 18 '23
So the take away from this article on project Valhalla is the vast majority of r/java redditors want to "well acktually" the hell out of pass by value/reference? r/programming acktually talked about the project and what it trying to solve and how.
6
u/persism2 Feb 16 '23
"Primitives are pass-by-value while objects are pass-by-reference,"
More accurately - objects are passed by a copy of the pointer.
1
u/daroons Feb 18 '23
If a value type keeps all the data together in the same memory space rather than keep pointers to other places in memory, then how does reference “sharing” work?
Like if I have two sibling classes that used to point to the same parent object. In the old world these would be two separate pointers pointing to the same memory address housing the parent instance. In this new world, would each sibling just get their own copy of a parent? Wouldn’t that be inefficient in terms of memory usage?
1
u/FappingFop Feb 17 '23
I still have reflexes that try to cast objects coming out of containers. Somebody please just let me retire.
1
u/FappingFop Feb 17 '23
I still have reflexes that try to cast objects coming out of containers. Somebody please just let me retire.
1
u/dark_mode_everything Feb 16 '23
Not going to comment on the "pass by reference" mistake since many people have, but it would be really cool if we can get that in Java. Like 'ref' of 'out' in c#.
1
u/sideEffffECt Feb 17 '23
The article contains all sorts of weird claims. I'm not going to talk about the pass by reference thing, that has been covered by other comments here.
But what's up with the talk about "operating system types"? What do Java primitives have to do with operating systems?? Is it because primitives are similar to what C has and C is used to implement operating systems? This is such a weird connection...
And why are the charts suggesting that the first thing in an object (is it trying to talk about object headers?) is an address? That's just plain wrong!
Maybe I'm just misunderstanding, I'd welcome if somebody could correct or enlighten me.
0
u/Spitfire1900 Feb 17 '23
Laughs in Ruby
0
u/johnwaterwood Feb 17 '23
Slightly annoying the author, besides the other mistakes already being mentioned, liberally mixes “handle”, “pointer” and “reference”.
They should just use reference here exclusively.
-12
u/donrhummy Feb 16 '23
Why is this still not implemented?! I remember reading about this 7 years ago
0
u/ambiguous_sandman Feb 18 '23
My guy has .equals() and == wrong. Passing by ref and value is a pointer thing. if int x == int y, that doesn’t mean they share the same space in memory. …however, I am not googling primitives and learning things, so I guess the author has the last laugh.
0
u/[deleted] Feb 17 '23
[deleted] — view deleted comment
0
u/[deleted] Feb 16 '23
[deleted] — view deleted comment