I saw many questions about this, and tried to solve the problem, but after one hour of googling and a lots of trial & error, I still can\'t fix it. I hope some of you ca
Consider the following case:
First, o1.compareTo(o2)
is called. card1.getSet() == card2.getSet()
happens to be true and so is card1.getRarity() < card2.getRarity()
, so you return 1.
Then, o2.compareTo(o1)
is called. Again, card1.getSet() == card2.getSet()
is true. Then, you skip to the following else
, then card1.getId() == card2.getId()
happens to be true, and so is cardType > item.getCardType()
. You return 1 again.
From that, o1 > o2
, and o2 > o1
. You broke the contract.