public class Utility {
public static final <T> void swap(T a, T b) {
T temp = a;
a = b;
b= temp;
}
public static final <T> void swapArr(T[] arr, int a, int b) {
T temp = arr[a];
arr[a] = arr[b];
arr[b] = temp;
}
}
why Utility.swap(a[i], a[j]);
won't correctly swap the two element of array, but Utility.swapArr(arr, i, j);
works fine?