public class ValueRefrence {
public static void main(String[] args) {
test1(); // 结果为 0 3
}
public static void test1() {
Integer i = new Integer(0);
//Integer@853 -----1
add(i);
//Integer@853 -----5
System.out.println(i);//0
i +=3;
//Integer@864 -----6
System.out.println(i);//3
}
static void add(Integer i) {
//Integer@853 -----2
i = i + 3;
//Integer@864 -----3
i = new Integer(i);//3
//Integer@865 -----4
}
}
网友评论