What is the reason why Wrapper classes (such as Integer, Double, etc.) do not have a setter for their internal primitive value?
I ask about this because such functionality will simplify the calculus and make the Java language a little more flexible.
Let me give you some examples.
1) Take the following example:
Integer x = new Integer(5); x++;
The previous code behind the scenes performs autoboxing. Sort of:
int x_tmp = x.intValue(); x_tmp++; x = new Integer(x_tmp);
Because of this problem, calculus execution on Wrapper is slower than execution on simple primitive types. With a setter, it would be easier to increase the internal value without allocating another object on the heap.
2) Another problem that pisses me off is the inability to write a swap function in Java, as I can do in C (using pointers) or in C ++ (pointers or links).
If I write void swap(Integer x, Integer y) , I can not get the internal value, because, and it will be impossible for me to change the values.
PS: A friend of mine suggested I consider the big picture and think in terms of concurrency and indicate immutability.
Do you have an explanation? Thanks!