标题:TreeSet
取消只看楼主
yu1543054075
Rank: 1
等 级:新手上路
帖 子:102
专家分:8
注 册:2015-4-30
结帖率:90.24%
已结贴  问题点数:20 回复次数:0 
TreeSet
class CustomComparator<T> implements Comparator<T> {
    public int compare(T o1, T o2) {
        if(((T) o1).equals(o2))
          return 0;
        return ((Comparable<T>) o1).compareTo((T) o2) * -1;
    }
}
下面三段代码不太清楚它的意思
if(((T) o1).equals(o2))//o1不是已经定义为T了吗,为什么还要强制转换为T,而o2为什么不需要
          return 0;
        return ((Comparable<T>) o1).compareTo((T) o2) * -1;//不明白什么意思

求指导!!!
搜索更多相关主题的帖子: compare public return equals 
2015-06-20 18:55



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-446820-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 1.064062 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved