If smell is a property of Cheese and not just of FrenchCheese you could use <br><br>when<br>
$person : Person ()<br>
$c: Cheese( eval( $c instanceof FrenchCheese), smell == "good" ) from $person.getLikes()<br>then<br><br>Also, I think that a selective retrieval with an overloaded version of getLikes():<br> getLikes( Class clazz )<br>
might be useful, avoiding useless elements in the returned collection.<br><br>-W<br><br><div class="gmail_quote">On 14 January 2011 12:02, Evert Penninckx <span dir="ltr"><<a href="mailto:evert.penninckx@gmail.com">evert.penninckx@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>
Hi<br>
<br>
I stumbled upon this problem last week. I see this is a very old post, and I<br>
was wondering if a "solution" has been implemented?<br>
<br>
It seems logical to me, that "from" only matches if an element in the list<br>
matches the required subclass. This means the classcast exception is catched<br>
and causes the rule not to match.<br>
rule "likes french cheese"<br>
when<br>
$person : Person ()<br>
FrenchCheese( smell == "good" ) from $person.getLikes()<br>
then<br>
System.out.println("likes french cheese");<br>
end<br>
This rule should only match FrenchCheese, even if other subclasses of Cheese<br>
are present in the set of Cheeses (getLikes()).<br>
<br>
<br>
They way I avoid it now is using an Enum containing each Cheese class (since<br>
I can't get it working with reflection).<br>
rule "likes french cheese"<br>
when<br>
$person : Person ()<br>
$cheese : Cheese( cheeseType == CheeseTypes.FrenchCheese ) from<br>
$person.getLikes()<br>
FrenchCheese( smell == "good" ) from $cheese<br>
then<br>
System.out.println("likes french cheese");<br>
end<br>
A bit awkward in my opinion. It would be nice if drools provided for the<br>
matching itself.<br>
<br>
<br>
So again, has this "problem" evolved since 2007?<br>
<br>
<br>
<br>
Greetz<br>
<br>
Evert<br>
<font color="#888888"><br>
<br>
<br>
--<br>
View this message in context: <a href="http://drools-java-rules-engine.46999.n3.nabble.com/About-for-and-inheritance-tp54110p2254750.html" target="_blank">http://drools-java-rules-engine.46999.n3.nabble.com/About-for-and-inheritance-tp54110p2254750.html</a><br>
Sent from the Drools - User mailing list archive at Nabble.com.<br>
_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</font></blockquote></div><br>