I am sorry I didn&#39;t mean &#39;for&#39; but &#39;from&#39;.<br>:D<br><br><div><span class="gmail_quote">2007/9/27, Chris Woodrow &lt;<a href="mailto:woodrow.chris@gmail.com">woodrow.chris@gmail.com</a>&gt;:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
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 &amp; constructors):<br><br><div style="margin-left: 40px;">

public class Cheese {<br>&nbsp;&nbsp;&nbsp;&nbsp;protected String name;<br>}<br><br>public class FrenchCheese extends Cheese{<br>&nbsp;&nbsp;&nbsp;&nbsp;private String smell;<br>}<br><br>public class Person {<br>&nbsp;&nbsp;&nbsp;&nbsp;private Cheese likes;<br>}<br></div><br>Here is my rule set :
<br><br><div style="margin-left: 40px;">package rules<br><br>rule &quot;likes cheese&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;when<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$person : Person ()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Cheese(&nbsp;&nbsp;) from $person.getLikes()<br>&nbsp;&nbsp;&nbsp;&nbsp;then <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println

(&quot;likes cheese&quot;);<br>end<br><br><br>rule &quot;likes french cheese&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;when<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$person : Person ()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FrenchCheese(&nbsp;&nbsp;) from $person.getLikes()<br>&nbsp;&nbsp;&nbsp;&nbsp;then <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println
(&quot;likes french cheese&quot;);
<br>end<br></div><br>First test :<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Cheese cheese = new FrenchCheese(&quot;good&quot;, &quot;camembert&quot;);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Person person = new Person();<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 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>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Cheese cheese = new Cheese();<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Person person = new Person();<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; person.setLikes(cheese);<br><br>Output :
<br><div style="margin-left: 40px;">likes french cheese<br>likes cheese<br></div><br>That&#39;s the first strange thing. As far as I am concerned, rule &quot;likes french cheese&quot; 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 &quot;likes french cheese&quot;<br>
&nbsp;&nbsp;&nbsp;&nbsp;when<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$person : Person ()<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FrenchCheese( smell == &quot;good&quot; ) from $person.getLikes()<br>
&nbsp;&nbsp;&nbsp;&nbsp;then <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(&quot;likes french cheese&quot;);<br>
end<br></div><br>Third test :<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Cheese cheese = new Cheese();<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Person person = new Person();<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; person.setLikes(cheese);<br><br>output : <br>It throwed an exception : Exception in thread &quot;main&quot; 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><span class="sg"><br>Chris<br>
</span></blockquote></div><br>