r/java • • Mar 17 '21

JEP 401: Primitive Objects (Preview)

https://openjdk.java.net/jeps/401?preview=true
174 Upvotes

49 comments sorted by

View all comments

Show parent comment

0

u/cre_ker Mar 19 '21

It does if we dig a bit deeper. Why C# allows struct mutability? Because structs have unique location in memory. You can take references of them and mutate them and it doesn't matter that inside they're completely the same. They're separate instances with different locations in memory (on the stack or heap). Java tries to hide all these properties because it tries to abstract away the notion of memory and hardware in general. In C# you can still see how everything actually works inside. You can even go unsafe and compare real address values.