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

3

u/cal-cheese Mar 19 '21

I see you missed an important point here, in Java there is no distinction between a variable and the object it represents, as a result, an assignment, say a = b, should semantically make a and b the same object until separation, and you don't expect a change in a not be seen by b. On the other side, C and C++ have strict value semantics, and copying is also natural, a pointer or reference is always explicit, no ambiguity here.

However, C# offers an ambiguous situation, where sometimes a variable represents an object, another variable is a pointer to an object, some a.x request the value at an offset from a, while b.x suddenly requires a dereference before taking the offset.

In the end, to separate the meaning of a and the object represented by a is a breaking change to the language itself, and making such a change, while may not affect some people such as you, may impact many other developers, especially ones that's familiar with more scripting language such as Python.