Suppose I have this in C++:
void test(int &i, int &j)
{
++i;
++j;
}
The values are altered inside the function and then use
You have to box it (your way) somehow.
Integer is immutable. so useless. int is mutable but since java is pass by value then its unusable again in that case. See these pages for more explanations: Java is Pass-by-Value, Dammit! and int vs Integer
Apache commons lang has a MutableInt class. Or you could write it yourself.
In any case, it should not be that bad because it should not happen often. If it does, then you should definitively change the way you code in Java.