2016-09-19 53 views
0

我有两个java对象(比方说Parent和Child..child扩展父对象)。但我只需要指定规则触发器,而不是针对其子对象。流口水规则只指定为其父孩子而不是为其子女打火机

例:

when 
    $raw : Parent() 
then 
    System.out.println(" Parent") 
end 
---- 
when 
    $raw : Child() 
then 
    System.out.println(" Child") 
end 

如果我尝试注入子对象作为一个事实,它火两种。我不能使用不是儿童()bz我有很多child.Thanks

最好的问候, Nipuna。

回答

0

首先,让我说,区分Parent对象和它的任何子类的必要性很可能是一个设计缺陷。如果您需要仅适用于家长而不适用于其任何子类的规则,则表示家长将要并行处理并将处理给其子女。要解决,请不要插入父对象,但要创建另一个子类

class ChildWithoutAdditionalProperties extends Parent { 
} 

并插入此类的对象。

第二,not Child()与除Child以外的任何其他类的对象不匹配,因为您的评论“我无法使用不是儿童()”似乎表明:它将匹配没有任何儿童事实。

要测试的对象是某一类的,你可以比较对象的类:

rule "parent" 
when 
    $e: Parent($e.getClass == Parent.class) 
then 
    System.out.println("found Parent"); 
end 
+0

这帮助了我很多。 Thanks.Appreciated。 –

相关问题