I don't understand why I get an Unchecked cast from Object to Compareable<Object>
because it is inside of a area that is only entered, if the instance is of a Compareable type. Can someone explain this to me and maybe give a solution, thanks.
My code looks like this. The problem is at line 8 and 9:
public int compare(Object one, Object two) {
if (one instanceof Vector && two instanceof Vector) {
Vector<? extends Object> vOne = (Vector<?>)one;
Vector<? extends Object> vTwo = (Vector<?>)two;
Object oOne = vOne.elementAt(index);
Object oTwo = vTwo.elementAt(index);
if (oOne instanceof Comparable && oTwo instanceof Comparable) {
Comparable<Object> cOne = (Comparable<Object>)oOne;
Comparable<Object> cTwo = (Comparable<Object>)oTwo;
if (ascending) {
return cOne.compareTo(cTwo);
} else {
return cTwo.compareTo(cOne);
}
}
}
return 1;
}