英文:
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.
专注分享java语言的经验与见解,让所有开发者获益!

评论