i have the following code that won't compile because of generic problems. It comes from when i try to run the code. The problem is that i must fix the generic issue but i can't spot it whether i must change something in the class StAlgo or in the method.
public class StAlgo{
//signature selection sort
public <T extends Comparable<T>> int selectionSort(T[] array) {
}
public static <T extends Comparable<T>> T[] getRandomPermutationOfIntegers(int size) {
T[] data = (T[])new Comparable[size];
for (Integer i = 0; i < size; i++) {
data[i] = (T)i;
}
// shuffle the array
for (int i = 0; i < size; i++) {
T temp;
int swap = i + (int) ((size - i) * Math.random());
temp = data[i];
data[i] = data[swap];
data[swap] = temp;
}
return data;
}
public <T extends Comparable<T>> void trySelectionSort(){
int N = 100, M = 100;
for(int i= 0; i < N; i++){
T[] arrayInts = (T[])new Comparable[i];
for(int j= 0; j < M; i++){
arrayInts = getRandomPermutationOfIntegers(i);
//Collections.shuffle(Arrays.asList(arrayInts));
selectionSort(arrayInts);
}
}
}
}
//Main class has the folling code:
StAlgosa s = new StAlgosa();
s.trySelectionSort();
I get the following error:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Bound mismatch: The generic method trySelectionSort() of type StAlgosa is not applicable for the arguments (). The inferred type Comparable<Comparable<T>> is not a valid substitute for the bounded parameter <T extends Comparable<T>>
how do i fix it?
thanks