If smell is a property of Cheese and not just of FrenchCheese you could use 

when
       $person : Person ()
       $c: Cheese( eval( $c instanceof FrenchCheese), smell == "good" ) from $person.getLikes()
then

Also, I think that a selective retrieval with an overloaded version of getLikes():
   getLikes( Class clazz )
might be useful, avoiding useless elements in the returned collection.

-W

On 14 January 2011 12:02, Evert Penninckx <evert.penninckx@gmail.com> wrote:

Hi

I stumbled upon this problem last week. I see this is a very old post, and I
was wondering if a "solution" has been implemented?

It seems logical to me, that "from" only matches if an element in the list
matches the required subclass. This means the classcast exception is catched
and causes the rule not to match.
rule "likes french cheese"
   when
       $person : Person ()
       FrenchCheese( smell == "good" ) from $person.getLikes()
   then
       System.out.println("likes french cheese");
end
This rule should only match FrenchCheese, even if other subclasses of Cheese
are present in the set of Cheeses (getLikes()).


They way I avoid it now is using an Enum containing each Cheese class (since
I can't get it working with reflection).
rule "likes french cheese"
   when
       $person : Person ()
       $cheese : Cheese( cheeseType == CheeseTypes.FrenchCheese ) from
$person.getLikes()
       FrenchCheese( smell == "good" ) from $cheese
   then
       System.out.println("likes french cheese");
end
A bit awkward in my opinion. It would be nice if drools provided for the
matching itself.


So again, has this "problem" evolved since 2007?



Greetz

Evert



--
View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/About-for-and-inheritance-tp54110p2254750.html
Sent from the Drools - User mailing list archive at Nabble.com.
_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users