public static void InsertionSort(Comparable[] a, int length){
for (int i = 1; i < length; i++){
for(int j = i; j > 0; j--){
if(a[j].compareTo(a[i]) > 0){
Integer b = (Integer)a;
swap(b, j, i);
}
else{
break;
}
}
}
}
public static void swap(Integer[] myArr,int a, int b){
int temp;
temp = myArr[a];
myArr[a] = myArr[b];
myArr[b] = temp;
}
Why is it not possible to downcast an interface to the instance implementing it? I would like to downcast a to an Integer type because a is comparable type. Then use the swap method which takes an Integer type but this is illegal.