title: Ways to avoid passing-by-reference in Java
body: <p>This question is probably as old as the hills. Nevertheless, after reading lots of articles and forums I still don't see a good solution to my problem.</p>
  
  <p>I have to transfer some Monte Carlo simulation programs from C++ to Java. The problem is that it heavily relies on passing variables by reference in functions, like:</p>
  
  <pre><code>void make_step(int &amp;a, int &amp;b, double &amp;c) {
     a++;
     b += a;
     c *= 1.1;
  }
  </code></pre>
  
  <p>There is no passing by reference in Java, as well as possible analogs, like multiple return values or nested functions. Solutions, which I have read on this site, usually involve encapsulation of primitive types into objects. Alternatively - break functions to single-return ones. However, in my case it results in too long and complicated code (few lines of C++ code grow to almost pages in Java). Also, since these algorithms are hard to debug, I want to avoid dramatical changes in code while porting.</p>
  
  <p>What I do now is substituting of all primitive type variables with arrays of length 1 (which are objects and can be modified inside functions). But it doesn't look like very elegant solutions. Does anyone have better ideas?</p>