I am getting the Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Comparison method violates its general contract!
for the code below:
@Override
public int compareTo(Employee o) {
if ((this.getStatus() == 1 && this.getSendBack() == 1)
&& (o.getStatus() == 1 && o.getSendBack() == 0))
return 1; // greater than
else if (this.getStatus() == 1 && o.getStatus() > 1)
return 0; // equal to
return -1; // less than
}
Additionally, this code is working for some of the conditions but it failing for some others. Moreover, I think this problem arises when I have some of the contradictory statements (please correct me if I am wrong), but I don't see having the same here.