Hi,<br>I recently find out a few issues using for, and I wanted to share it with you. I made a simple exemple to illustrate my purpose.<br><br>My classes are (I did not represent accessors & constructors):<br><br><div style="margin-left: 40px;">
public class Cheese {<br> protected String name;<br>}<br><br>public class FrenchCheese extends Cheese{<br> private String smell;<br>}<br><br>public class Person {<br> private Cheese likes;<br>}<br></div><br>Here is my rule set :
<br><br><div style="margin-left: 40px;">package rules<br><br>rule "likes cheese"<br> when<br> $person : Person ()<br> Cheese( ) from $person.getLikes()<br> then <br> System.out.println
("likes cheese");<br>end<br><br><br>rule "likes french cheese"<br> when<br> $person : Person ()<br> FrenchCheese( ) from $person.getLikes()<br> then <br> System.out.println("likes french cheese");
<br>end<br></div><br>First test :<br> Cheese cheese = new FrenchCheese("good", "camembert");<br> Person person = new Person();<br> person.setLikes(cheese);<br><br>Output :<br><div style="margin-left: 40px;">
likes french cheese<br>likes cheese<br></div><br>Wich is expected...<br><br>Second test : <br> Cheese cheese = new Cheese();<br> Person person = new Person();<br> person.setLikes(cheese);<br><br>Output :
<br><div style="margin-left: 40px;">likes french cheese<br>likes cheese<br></div><br>That's the first strange thing. As far as I am concerned, rule "likes french cheese" should not match (since a Cheese is not a FrenchCheese).
<br><br>I made a change to the second rule :<br><div style="margin-left: 40px;">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></div><br>Third test :<br> Cheese cheese = new Cheese();<br>
Person person = new Person();<br>
person.setLikes(cheese);<br><br>output : <br>It throwed an exception : Exception in thread "main" java.lang.ClassCastException: rules.Cheese<br>I am not saying the ClassCastException is not to expect in such a case but I think I would simply expect it not to match (as far as a Cheese is not a FrenchCheese).
<br><br>Chris<br>