我正在阅读 Drools 6.4.0 documentation .我不确定是否理解 contains
和 memberof
运算符之间的区别:两者都适用于集合,似乎唯一的区别是 contains
期望包含的对象在右侧,而 memberof
期望它在左侧,所以它们是等价的,但恐怕我遗漏了一些东西。
最佳答案
这个例子摘自 Laune 的回答: Drools: Match local string from array in LHS of rule
rule "ruleY"
when
Data( $los: listOfStrings )
MyObject( string memberOf $los )
then
//do stuff
end
rule "ruleY"
when
MyObject( $s: string )
Data( listOfStrings contains $s )
then
//do stuff
end
它们是互补的。根据您拥有的数据和最合乎逻辑的表达方式来使用其中一种。
关于Drools:contains 和 memberof 之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37986320/