Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

java.lang.IllegalArgumentException: Comparison method violates general.....

1004808Apr 23 2013 — edited Apr 23 2013
Below code throws java.lang.IllegalArgumentException: Comparison method violates its general contract!,

Collections.sort( arrayList, new Comparator()
{
public int compare( Object o1, Object o2 )
{
TypeAdapterSort tas1 = ( TypeAdapterSort ) o1;
TypeAdapterSort tas2 = ( TypeAdapterSort ) o2;
if ( tas1.order < tas2.order )
return -1;
else
return 1;
}
} );

class TypeAdapterSort {
int order;
}

I am not sure with what data in arraylist the above code throws the exception, please me know the data that needs to be populated in arraylist so that the exception occurs.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 21 2013
Added on Apr 23 2013
12 comments
3,315 views