我正在尝试对TreeSet进行扩展并将其放入我自己的比较器中。实现Comparator接口不起作用:
class MyTreeSet<E> extends TreeSet<E> implements Comparator<E>{
// the required implementation of the abstract compare(E,E):
public int compare(E e1, E e2)
{
// ...
}
}
从
获得的null证明(new MyTreeSet<E>).comparator()
我意识到可以获得具有任意比较器的普通TreeSet作为
TreeSet<E> = new TreeSet<>(MyComparator<E> ctor)
我已经单独定义了MyComparator。但我需要一个MyTreeSet,它是TreeSet的扩展。那可能吗?感谢。