Comparison method violates its general contract Exception

后端 未结 1 1818
日久生厌
日久生厌 2020-12-11 22:40

Below is a block of code that results in exception as indicated,

Code :

Collections.sort( arrayList, new Comparator() 
{
    public int compare( Obje         


        
1条回答
  •  时光说笑
    2020-12-11 23:34

    You need to return 0 on equal objects.

            if ( tas1.order < tas2.order ){
                return -1;
            } else if ( tas1.order == tas2.order ){
                return 0;
            } else {
                return 1;
            }
    

    You can read here more

    0 讨论(0)
提交回复
热议问题