I'm trying to make a general function that takes in an array of Unknown type and flips it. It doesn't return anything and should pass a reference to the array to the function.
I've tried to use Varargs:
public static <Unknown> void reverseArray(Unknown... a){
Unknown t;
for(int i=0;i<a.length/2;i++){
t = a[i];
a[i] = a[a.length - i - 1];
a[a.length - i - 1] = t;
}
}
But that doesn't work for primtives because java doesn't seem to pass in a reference to an array I've tried Object[]
public static void reverseArray(Object[] a){
Object t;
for(int i=0;i<a.length/2;i++){
t = a[i];
a[i] = a[a.length - i - 1];
a[a.length - i - 1] = t;
}
}
But when when I pass it int[]
java says it is not applicable for the arguments (int[])
Same thing with generics:
public static <Unknown> void reverseArray(Unknown[] a){
Unknown t;
for(int i=0;i<a.length/2;i++){
t = a[i];
a[i] = a[a.length - i - 1];
a[a.length - i - 1] = t;
}
}