Fixed the "Comparator and Comparable in Java" Article
This commit is contained in:
@@ -45,7 +45,7 @@ public class Player implements Comparable<Player> {
|
||||
|
||||
@Override
|
||||
public int compareTo(Player otherPlayer) {
|
||||
return (this.getRanking() - otherPlayer.getRanking());
|
||||
return Integer.compare(getRanking(), otherPlayer.getRanking());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ public class PlayerAgeComparator implements Comparator<Player> {
|
||||
|
||||
@Override
|
||||
public int compare(Player firstPlayer, Player secondPlayer) {
|
||||
return (firstPlayer.getAge() - secondPlayer.getAge());
|
||||
return Integer.compare(firstPlayer.getAge(), secondPlayer.getAge());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ public class PlayerRankingComparator implements Comparator<Player> {
|
||||
|
||||
@Override
|
||||
public int compare(Player firstPlayer, Player secondPlayer) {
|
||||
return (firstPlayer.getRanking() - secondPlayer.getRanking());
|
||||
return Integer.compare(firstPlayer.getRanking(), secondPlayer.getRanking());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user