“Comparison method violates its general contract!”

前端 未结 11 2087
梦如初夏
梦如初夏 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:53

    If compareParents(s1, s2) == -1 then compareParents(s2, s1) == 1 is expected. With your code it's not always true.

    Specifically if s1.getParent() == s2 && s2.getParent() == s1. It's just one of the possible problems.

提交回复
热议问题