class MyComparator<Integer> implements Comparator<Integer>
{
@Override
public int compare(Integer o1, Integer o2) {
if(o1>o2) // line no 3
return 1;
else if(o1==o2)
return 0;
else
return -1;
}
}
Run Code Online (Sandbox Code Playgroud)
在第3行,既没有取消装箱,也没有能够调用intValue().请帮助理解这一点.
在第3行,编译错误即将来临.
您应该删除<Integer>在MyComparator<Integer>.这里发生的是你声明Integer一个类型变量.它不是java.lang.Integer,它只是编译器一无所知的一些类型变量.
| 归档时间: |
|
| 查看次数: |
61 次 |
| 最近记录: |