public static void main(String[] args) {
Test A = new Test();
Test B = new Test();
A.setValue(10);
B.setValue(12);
IntegerTest tt = new IntegerTest();
System.out.println("Before A = " + A.getValue());
System.out.println("Before B = " + B.getValue());
tt.swap(A, B);
System.out.println("After A = " + A.getValue());
System.out.println("After B = " + B.getValue());
}
public void swap(Test A, Test B) {
int tmp = A.getValue();
A.setValue(B.getValue());
B.setValue(tmp);
}
}
class Test {
int a;
public void setValue(int a) {
this.a = a;
}
public int getValue() {
return a;
}
}
Before A = 10
Before B = 12
After A = 12
After B = 10
public static void swap(Integer a, Integer b){}又能实现不?
[/Quote]
答:
public static void swap(int a,int b){} 不行
public static void swap(Integer a, Integer b){} 不行