无法解析“t”中的方法“compareto”

oogrdqng  于 2021-07-14  发布在  Java
关注(0)|答案(0)|浏览(321)

我不断得到错误,无法解析“t”中的方法“compareto”,并且不确定是什么错误。泛型类t将实现comparable并具有compareto方法。我正在尝试使用泛型类“t”中的compareto方法。我还是个初学者,所以有什么建议可以帮助我:)

public class Tester<T> implements Comparable<Tester>{
public int value;
private T index;

public Tester(int item1, T item2){
    value = item1;
    index = item2;
}

@Override
public int compareTo(Tester o) {
    return this.index.compareTo(o.index);
}

我也尝试过这样改变函数:

public class Tester<T> implements Comparable<T> {
public int value;
private T index;

public Tester(int item, T item2){
    value = item;
    index = item2;
}

@Override
public int compareTo(T o) {
    return this.index.compareTo(o);
}

我也试过这个:

public class Tester<T> implements Comparable {
public int value;
public T index;

public Tester(int item, T item2){
    value = item;
    index = item2;
}

@Override
public int compareTo(Object o) {
    Ticket b = (Ticket)o;
    return this.index.compareTo(b.index);
}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题