I am new to Java and facing a problem in declaring generic array as static. I need your help to solve and understand what is going wrong.
public class ThreadedSorter<E> {
private static int number_of_threads = 2;
private static E[] array, aux;
....
public static <E> E[] mergeSort(E[] unsortarray) {
array = unsortarray;
.....
return array;
}
private static void mergeSortHelper(int low, int hi) {
if(low==hi) return;
int mid = (low+hi) >> 1;
mergeSortHelper(low,mid);
mergeSortHelper(mid+1, hi);
merge(low,mid+1,hi);
}
private static void merge(int low, int hi, int upperBound) {
.....
while(low <=mid && hi <= upperBound)
if(array[low] <= array[hi])
aux[j++] = array[low++];
........
}
endclass
I am facing issue for following declaration - saying non static type variable can not be referenced from a static context.
"private static E[] array, aux;"
Can you please tell me where I am missing.
Regards, Pratik