我不明白为什么我会得到一个,Unchecked cast from Object to Compareable<Object>因为它位于仅输入的区域内,如果实例是可比较类型的话。有人可以向我解释一下,也许可以给出解决方案,谢谢。
我的代码看起来像这样。问题出在第 8 行和第 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;
}