请都高手,在java中传址怎么实现?
class Swap
{
public static void main(String args[])
{
Integer a, b;
int i,j;
a = new Integer(10);
b = new Integer(50);
i = 5;
j = 9;
System.out.println( "Before Swap, a is " + a);
System.out.println( "Before Swap, b is " + b);
swap(a, b);
System.out.println( "After Swap a is " + a);
System.out.println( "After Swap b is " + b);
System.out.println( "Before Swap i is " + i);
System.out.println( "Before Swap j is " + j);
swap(i,j);
System.out.println( "After Swap i is " + i);
System.out.println( "After Swap j is " + j);
}
public static void swap(Integer ia, Integer ib)
{
Integer temp = ia;
ia = ib;
ib = temp;
}
public static void swap(int li, int lj)
{
int temp = li;
li = lj;
lj = temp;
}
}
上面程序的输出是:
Before Swap, a is 10
Before Swap, b is 50
After Swap a is 10
After Swap b is 50
Before Swap i is 5
Before Swap j is 9
After Swap i is 5
After Swap j is 9
我所期望的是在我调用 swap函数后,a,b的值都改变,i,j也是都改变,实际上没有改变,
我应如何去做呢?请高手相助.