I am getting "comparison method violates its general contract" Exception in my application so I tried to create the dummy compare To method in standalone application as mentioned below but not able to replicate the issue.
Can someone please help me to troubleshoot issue,
Here I have created Employee Class and implemented java.lang.Comparable
interface for that class
public int compareTo(Employee arg0) {
StringBuffer sb = new StringBuffer();
StringBuffer sb2 = new StringBuffer();
sb.append(getEmpId())
.append(",")
.append(getFirstName())
.append(",")
.append(getLastName());
sb2.append(arg0.getEmpId())
.append(",")
.append(arg0.getFirstName())
.append(",")
.append(arg0.getLastName());
return sb.toString().compareToIgnoreCase(sb2.toString());
}
for this compareTo
method I am facing mentioned exception in my enterprise application.
Volunteer help is appricated.
I am using JDK version 1.7.0_201.