比较 JBoss Drools 中同一类的对象
我有一个简单的问题 - 是否可以在 Drools 中比较同一类的两个对象?如果是,我如何区分这两个对象?
I have a quick question - is it possible to compare two objects of the same class in Drools? And if yes, how do I distinguish between the two objects?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的。
第一个和第二个属于同一类,但不同的实例。
Yes.
first and second are of the same class, but different instances.
回答您的后续问题。是的,两个对象都需要位于工作内存中才能激活规则。在托尼的示例中,“first”绑定到第一个对象,“second”绑定到第二个对象(即您将使用“first”访问第一个对象)。要访问对象上的方法,您可以使用 mvel/java 语法,例如first.userId 或first.getUserId()。因此,要查看 WM 中是否有两个不同的对象具有相同的用户 ID:
注意,按照惯例,您经常会看到模式绑定变量前面带有“$”前缀。
哈
To answer your follow-up. Yes, both objects would need to be in working memory for the rule to be activated. In Toni's example "first" is bound to the first object and "second" the second (ie you'd use "first" to access the first object). To access methods on the object you can use mvel/java syntax like first.userId or first.getUserId(). Thus, to see if there are two different Objects in WM with the same userid:
Note, by convention you'll often see the pattern binding variable prefixed with "$" as above.
hth