java中有类似C#里ref或out的功能吗?
如题,在编程过程中可能会遇到调用自定义函数对一些数据进行处理,如:
public static void main(String[] args)
{
....
int x = 1, y = 2;
swap(x, y);
System.out.println("x = " + x + ", y = " + y);
....
}
//互换两个数
static void swap(int x, int y)
{
x = x + y;
y = x - y;
x = x - y;
}
有什么办法让x=2,y=1
不用对象封装引用传递的方法,而是像C#里的ref那样,向各位大侠请教。