无法找到“java.lang.IllegalArgumentException:比较方法违反其总合同的解决方案!”

时间:2018-02-28 17:05:24

标签: java comparison

这是我的代码:

Collections.sort(ordered_neighborhood, (m1, m2) -> {
      double improvM1 = 0, improvM2 = 0, occurrM1 = 0, occurrM2 = 0;
      improvM1 = getImprovementsRate(moveStatsList, m1);
      improvM2 = getImprovementsRate(moveStatsList, m2);
      occurrM1 = getOccurrencesRate(moveStatsList, m1);
      occurrM2 = getOccurrencesRate(moveStatsList, m2);
      int costM1 = (int) (((m1.after - m1.before) - improvM1 + occurrM1) * 1000);
      int costM2 = (int) (((m2.after - m2.before) - improvM2 + occurrM2) * 1000);
      int r = (costM1 - costM2);
      return r;
    });

getImprovementsRatemoveStatsList获取m1m2的属性,该属性在比较期间不会更改。 getOccurrencesRate

也是如此

m1.after - m1.before = 0使m1m2等于,但我会用两个权重数组加权m1m2

我看到了"Comparison method violates its general contract!"问题,但问题是每次运行程序时错误都不会进行比较。这似乎是不确定的。 也许从double转换为int

0 个答案:

没有答案