Discuss / Java / compareTo() 方法

compareTo() 方法

Topic source

//按分数从小到大顺序排序  如果 分数 一样 按姓名字典顺序 排序

@Override
public int compareTo(Person other) {

int score = this.score - other.score;

if (score == 0) {
score = this.name.compareTo(other.name);
}

return score;
}

🌙

#2 Created at ... [Delete] [Delete and Lock User]

现在也不明白当时的脑回路是什么了.为什么要这样写.

🌙

#3 Created at ... [Delete] [Delete and Lock User]

现在看,如行云流水,和呼吸一样自然。。。

🌙

#4 Created at ... [Delete] [Delete and Lock User]

我觉得这可能和人的本能有关系,对陌生的事物莫名的害怕,见多了,也就那样


  • 1

Reply