Hey guys I have this code to compare by duration but I keep getting this error:
Fatal Exception: java.lang.IllegalArgumentException Comparison method violates its general contract!
Here is my code:
Collections.sort(list, new Comparator<MyProduct>() {
@Override
public int compare(MyProduct lhs, MyProduct rhs) {
Integer lDuration = (lhs != null ? lhs.getDuration() :0);
Integer rDuration = (rhs != null ? rhs.getDuration() :0);
return lDuration.compareTo(rDuration);
}
});