Hi Ranchers,
I read on the Core
Java Vol 1, that:
Wrapper classes are immutable - you cannot change a wrapped value after the wrapper has been constructed.
I understood this piece of information to imply that once you construct a wrapped object holding a value of (e.g 3),
then you cannot change that value to (e.g. 4).
code:
----
public static void main(
String[] args) {
Integer i = 3;
System.out.println("initial value: " + i); // line 1: prints 3
//change the wrapped value
n++;
System.out.println("final value: " + i); // line 2: prints 4
}
----
I expected that the output of line 2, would print 3 (as it is said that you cannot change that value of a wrapped object), but instead the output is 4.
Can anyone please help me understand?
Regards,
Siphiwe Madi