0

我有这堂课:

public abstract class Orderable<ID, T extends Comparable, V extends Orderable> implements Comparator<V>{
public abstract ID getId();
public abstract T getOrderParam();

public int compare(V o1, V o2) {
    int compared = o1.getRankParam().compareTo(o2.getRankParam());
    if (compared == 0) return o2.getId().toString().compareTo(o1.getId().toString());
    return compared;
}

现在我想创建一个 ConcurrentSkipListMap 作为我在 Orderable 类中定义的 Comparator 传递。目标是使用 V 的比较器保持 ConcurrentSkipListMap 有序,其中 V 是扩展 Orderable 的泛型类。

    private volatile ConcurrentSkipListMap<ID, V> concurrentSkipListMap;
private volatile AtomicInteger size;

public LeaderBoardImpl() {
    concurrentSkipListMap = new ConcurrentSkipListMap<ID, V>(**** HERE I NEED TO PASS COMPARATOR****);
    size = new AtomicInteger(0);
}

我不确定如何传递泛型类的比较器。谢谢阿尔伯特

4

0 回答 0