How do I use an equivalent to C++ reference parameters in Java?

后端 未结 11 1329
借酒劲吻你
借酒劲吻你 2020-12-09 14:33

Suppose I have this in C++:

void test(int &i, int &j)
{
    ++i;
    ++j;
}

The values are altered inside the function and then use

11条回答
  •  醉话见心
    2020-12-09 15:09

    Java has no equivalent of C++ references. The only way to get this to work is to encapsulate the values in another class and swap the values within the class.

    Here is a lengthy discussion on the issue: http://www.yoda.arachsys.com/java/passing.html

提交回复
热议问题