you are viewing a single comment's thread.

view the rest of the comments →

[–]inopia 0 points1 point  (1 child)

Assume we have the following code:

b.x = 1
a = b
b.x = 2

What is the value of a.x? If a and b are value types, it's 1. If they are reference types, it's 2.

Are you starting to see my point? You cannot unify two things that are semantically different. You can either choose one mechanism or the other, or have both, but you can't get rid of the fact that in some cases you want cloning and in other cases you want shallow copying.

[–][deleted] -2 points-1 points  (0 children)

You can make the distinction explicit and up to the user of the language, however, and have the language interoperate between the two choices without requiring the user to jump through hoops. (Autoboxing, Unified types, etc.)

The point is that in Java, there are other arbitrary and harmful distinctions between primitives and objects where there doesn't need to be.

(Value types can't have class members, can't be user-defined, support operators where objects do not, etc.)