无法解析方法 'CompareTo(int)'

Cannot resolve method 'CompareTo(int)'

我正在尝试使用冒泡排序和 compareTo 方法对对象数组进行排序。 IF 条件中的“.compareTo”不起作用,并显示无法解析方法 'CompareTo(int)' 我该如何解决这个问题?

我的排序方式:

public static void sort(Card[] hand) {
    
    for (int i = 1; i < hand.length; i++) {
        for (int j = 0; j < hand.length - i; j++) {
            if (((hand[j].getRankValue()).compareTo((hand[j + 1].getRankValue()))) > 0) {
                Card temp = hand[j];
                hand[j] = hand[j + 1];
                hand[j + 1] = temp;
            }
        }
    }
}

public class Card {

public final int suit;
public final int rank;
public int rankValue = 0;

public static final String[] SUIT = {
        "Hearts", "Clubs", "Diamonds", "Spades"};

public static final String[] RANK = {
        "2", "3", "4", "5", "6", "7",
        "8", "9", "10", "Jack", "Queen", "King", "Ace"};

public Card(int rank, int suit) {
    this.rank = rank;
    this.suit = suit;
    this.rankValue = getRankValue();
}

public int compareTo(Card other){
    if(getRankValue() > other.getRankValue()) return 1;
    else if(getRankValue() < other.getRankValue()) return -1;
    else return 0;
}

public int getRank(){
    return this.rank;
}

public int getSuit(){
    return this.suit;
}

public int getRankValue() {
    return this.suit * 13 + this.rank - 1;
}

public String toString() {
    return RANK[this.rank] + " of " + SUIT[this.suit];
}

}

您的 compareTo() 函数比较两张牌,因此您的 if 语句中不需要任何 getRankValues()。如果你摆脱了那些,你的代码应该可以工作。