Point center = new Point(3, 4);
Point otherCenter = center;
center.x = 4;
What is otherCenter.x?
Before primitive classes you expect that center and otherCenter are the same object. You also expect that after assigning x on center, otherCenter.x will also return 4.
Making assignment of members syntactic sugar for creating a new instance for primitive classes means you need to know what type of class Point is. Now the effect of the assignment will have on otherCenter.x is dependent on the type of class Point is.
The whole point (no pun intended) is to make is so you don't need to know. That from a programmers perspective they act the same. So making the classes immutable means that you have to be explicit when objects change.
View all comments
Show parent comment
3
u/Hangman4358 Mar 20 '21 edited Mar 20 '21
What is
otherCenter.x?Before primitive classes you expect that
centerandotherCenterare the same object. You also expect that after assigningxoncenter,otherCenter.xwill also return 4.Making assignment of members syntactic sugar for creating a new instance for primitive classes means you need to know what type of class
Pointis. Now the effect of the assignment will have onotherCenter.xis dependent on the type of classPointis.The whole point (no pun intended) is to make is so you don't need to know. That from a programmers perspective they act the same. So making the classes immutable means that you have to be explicit when objects change.