A question about immutable object: Integer
807591Feb 22 2008 — edited Mar 5 2008import java.lang.Integer;
public class ImmutableObject {
public void changeImmutable(Integer x){
x = x+1;
System.out.print(x );
}
public static void main(String[] args){
Integer x = new Integer(1);
ImmutableObject i= new ImmutableObject();
i.changeImmutable( x);
System.out.print( x);
}
}
Hello everyone,
Why the output of the program above is 21 rather than 22?
Is it because of +? Can anyone tell me about this?
Thanks a lot.
Kolapig