Optaplanner的Joiners.equal方法是否没有使用.equals方法?

huangapple go评论59阅读模式
英文:

Optaplanner Joiners.equal not using .equals?

问题

我在我的OptaPlanner项目中定义了一个约束(使用Constraint-Stream-API),起始部分如下:

factory.from(Lesson.class)
        .join(Lesson.class, equal(Lesson::getTimeslot, Lesson::getTimeslot))...

Timeslot类中,我已经重写了equals()方法。
然而,对我来说,似乎Joiners.equal并没有使用这个equals方法来比较时间段(Timeslot),因为我在使用以下代码时得到了不同的结果:

factory.from(Lesson.class).join(Lesson.class)
        .filter((l,m) -> l.getTimeslot().equals(m.getTimeslot())

有人知道Joiners.equal根据什么基础进行比较吗?

英文:

Im defining a Constraint im my OptaPlanner project (using Constraint-Stream-API) starting in the following way:

factory.from(Lesson.class)
        .join(Lesson.class, equal(Lesson::getTimeslot, Lesson::getTimeslot))...

In the Class Timeslot i have overridden the equals()-method.
To me it seems however that Joiners.equal doesnt use this equals Method to compare the timeslots, because i get different result using the following code:

 factory.from(Lesson.class).join(Lesson.class)
        .filter((l,m) -> l.getTimeslot().equals(m.getTimeslot())

Does anyone know on what basis Joiners.equal does its comparison?

答案1

得分: 2

Joiners.equal 依赖于 equals() hashCode() 同时满足 Java equals/hashCode 合约,正如Java语言规范所定义。

英文:

Joiners.equal relies on equals() and hashCode() both fullfilling the Java equals/hashCode contract, as defined by the Java Language Spec.

huangapple
  • 本文由 发表于 2020年4月5日 16:02:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/61039679.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定