How to pass by "reference" Java
I'm coming from C++ background programming and, it's easy to pass by reference a variable to change it inside the function. Just doing: void foo(int& n) { ++n; } But, in Java I can't find an easy way to do it without importing another things. I know that in java is pass by value so, any primitive type will be passed by value. I'm interested in primitive types. I googled and stack overflow offers some solutions: https://stackoverflow.com/questions/4319537/how-do-i-pass-a-primitive-data-type-by-reference My teacher used a Length 1 primitive array (check stackoverflow link) but, is dirty for me. The other solutions doesn't convinced me too much... Is there a fast and elegant way to pass a primitive data type by reference? And if not, for Java programmers veterans, what's the best way to pass by "reference" a primitive data type?