【发布时间】:2018-02-18 20:31:56
【问题描述】:
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;
}
}
在第 3 行,既没有拆箱,我也无法调用 intValue()。请帮助理解这一点。
在第 3 行,编译错误来了。
【问题讨论】:
-
你为什么认为那些是
java.lang.Integer对象? -
错误是什么?
-
如果你有整数对象,为什么不使用
Integer#compareTo? -
我可以使用它,但我很想知道为什么它不起作用。
-
你认为
MyComparator<Integer>会做什么?
标签: java