public static class Nodez <E extends Comparable<E>> implements Comparable<Nodez<E>>{
public String x;
public E node;
public String get(){
return x;
}
@Override
public int compareTo(Nodez<E> node) {
return node.x.compareTo(x);
}
}
public static void main(String[] args) throws IOException
{
Function<String, PrintStream> printUpperCase = x -> System.out.printf("%S", x);
TreeSet<Nodez<String>> bstTest = new TreeSet<>();
Nodez<String> e1 = new Nodez<>();
e1.x = "fresh";
bstTest.add(e1);
System.out.println(bstTest.contains(e1));
}
然而,我认为节点应该能够接受任何可比较的泛型类型,在这种情况下,它的顺序应该更像这样:
public static class Nodez <E extends Comparable<E>> implements Comparable<Nodez<E>>{
public E x;
public Nodez<E> node;
public E get(){
return x;
}
@Override
public int compareTo(Nodez<E> node) {
return node.x.compareTo(x);
}
}
public static void main(String[] args) throws IOException
{
Function<String, PrintStream> printUpperCase = x -> System.out.printf("%S", x);
TreeSet<Nodez<String>> bstTest = new TreeSet<>();
Nodez<String> e1 = new Nodez<>();
e1.x = "fresh";
bstTest.add(e1);
System.out.println(bstTest.contains(e1));
}