英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论