“Comparison method violates its general contract!”

前端 未结 11 2042
梦如初夏
梦如初夏 2020-11-21 06:07

Can someone explain me in simple terms, why does this code throw an exception, \"Comparison method violates its general contract!\", and how do I fix it?

pri         


        
11条回答
  •  温柔的废话
    2020-11-21 06:56

    I've seen this happen in a piece of code where the often recurring check for null values was performed:

    if(( A==null ) && ( B==null )
      return +1;//WRONG: two null values should return 0!!!
    

提交回复
热议问题