I am Ph.D. student in Computer Science at King Abdullah University of Science & Technology (KAUST).
Wednesday, April 30, 2008
Pass an integer by reference
Sometimes you may need to pass an integer to be able to change its value. "integer" are always passed by value in Java. An easy way to pass by reference is to use a single element array.
int[] a = new int[1]; a[0] = 1; add2(a); // a[0] now = 3 ...
No comments:
Post a Comment