私はintで満たされたリストを持っています:
List collection = new ArrayList();
collection.add(this.score1);
collection.add(this.score2);
collection.add(this.score3);
ここで、最高スコアと個々のスコアを比較して、どれが最高かを確認したいと思います。直感的に私はそれを次のようにしようとしました:
String highestScore;
if(Collections.max(collection) == this.score1) {
highestScore = "Score 1";
}
if(Collections.max(collection) == this.score2) {
highestScore += ", Score 2";
}
if(Collections.max(collection) == this.score3) {
highestScore += ", Score 3";
}
でも、
Collections.max(collection) == this.score1
Collections.max(collection) == this.score2
Collections.max(collection) == this.score3
すべて私にエラーを与えます:
互換性のないオペランド型 Comparable と int
ただし、これはうまくいくようです:
int highestScoreValue = Collections.max(collection);
さて、それはどのようにできますか?
Java で int を に設定Collections.max(collection)
できるのに、int を と比較できないのはなぜCollections.max(collection)
ですか?