Code: Select all
public class Test{
public static void testInts(Integer obj, int var){
obj = var++;
obj++;
}
public static void main(String[] args) {
Integer val1 = new Integer(5);
int val2 = 9;
testInts(val1++, ++val2);
System.out.println(val1+" "+val2);
}
}
When testInts is executed, val1 is set to a new Integer(6), val2 is set to 10.
5 and 10 are then passed as arguments, but since obj is set to point to the var++ object, obj no longer has any relation to val1?
If my thinking is correct then if "obj = var++;" was removed, val1 would be set to a new Integer(7) object, and the result would print 7, 10?
Hopefully I'm understanding this correctly.