No matter the type of a variable or whether it is inmutable or not, if you reassign a variable inside a method you are not going to see that change outside the method. Each method in java receives a copy of the variable (pointing to the same object of course) we are passing. Changing the object reference of the variable inside a method is not going to affect the original variable.<div>

<br></div><div>@Abhinay, the truth is that Drools transforms the RHS of a rule is into a java class. And, just like Wolfgang says, globals are stored in some kind of Map, so you must use setGlobal() if you want to change the value of a global in drools.</div>

<div><br></div><div>Best Regards,     <br clear="all"><br>XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX<br><br>Esteban Aliverti<br>- Blog @ <a href="http://ilesteban.wordpress.com" target="_blank">http://ilesteban.wordpress.com</a><br>


<br><br><div class="gmail_quote">On Mon, Jul 16, 2012 at 2:08 PM, Wolfgang Laun <span dir="ltr">&lt;<a href="mailto:wolfgang.laun@gmail.com" target="_blank">wolfgang.laun@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

It may not be quite so simple as that - using int to illustrate a<br>
problem occuring with Integer is misleading.<br>
<br>
An Integer is an immutable object.<br>
   Integer a = Integer.valueOf( 42 );<br>
   a += 1<br>
You&#39;ll certainly still have an Integer object available via &#39;a&#39;, but<br>
it&#39;s *not* the one containing 42 any more - that&#39;s already in the<br>
garbage.<br>
<br>
The situation is aggravated by the fact that a &#39;global&#39; is stored in a<br>
sort of container and this container is not directly accessible for<br>
effecting a change, only via setGlobal().<br>
<span class="HOEnZb"><font color="#888888"><br>
-W<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
On 16/07/2012, Esteban Aliverti &lt;<a href="mailto:esteban.aliverti@gmail.com">esteban.aliverti@gmail.com</a>&gt; wrote:<br>
&gt; Let&#39;s say you have this method in a java class:<br>
&gt;<br>
&gt; public void addOne(int number){<br>
&gt;    number = number +1;<br>
&gt; }<br>
&gt;<br>
&gt;<br>
&gt; And let&#39;s say you want to invoke that method from another method in the<br>
&gt; same (or a different. It doesn&#39;t matter) object:<br>
&gt;<br>
&gt; int number = 0;<br>
&gt; this.addOne(number);<br>
&gt; System.out.println(&quot;Number= &quot;+number);<br>
&gt;<br>
&gt; What is the output of the code above? Figure out that and you will figure<br>
&gt; out what is happening with your global.<br>
&gt;<br>
&gt; Best Regards,<br>
&gt;<br>
&gt; XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX<br>
&gt;<br>
&gt; Esteban Aliverti<br>
&gt; - Blog @ <a href="http://ilesteban.wordpress.com" target="_blank">http://ilesteban.wordpress.com</a><br>
&gt;<br>
&gt;<br>
&gt; On Mon, Jul 16, 2012 at 11:53 AM, abhinay_agarwal &lt;<br>
&gt; <a href="mailto:abhinay_agarwal@infosys.com">abhinay_agarwal@infosys.com</a>&gt; wrote:<br>
&gt;<br>
&gt;&gt; global java.lang.Integer count<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; rule &quot;rule1&quot;<br>
&gt;&gt; agenda-group &quot;1&quot;<br>
&gt;&gt; when<br>
&gt;&gt;        //smething<br>
&gt;&gt; then<br>
&gt;&gt;       count=0;<br>
&gt;&gt;       System.out.println(count); // output is 0<br>
&gt;&gt;       count = count +1;<br>
&gt;&gt;       System.out.println(count); // output is 1<br>
&gt;&gt;       drools.setFocus(&quot;2&quot;);<br>
&gt;&gt; end<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; rule &quot;rule2&quot;<br>
&gt;&gt; agenda-group &quot;2&quot;<br>
&gt;&gt; when<br>
&gt;&gt;        //smething<br>
&gt;&gt; then<br>
&gt;&gt;       System.out.println(count); // output is 0<br>
&gt;&gt; end<br>
&gt;&gt;<br>
&gt;&gt; in the rule2, the value of the global variable &quot;count&quot; must be 1, why m i<br>
&gt;&gt; getting it as zero ?<br>
&gt;&gt;<br>
&gt;&gt; --<br>
&gt;&gt; View this message in context:<br>
&gt;&gt; <a href="http://drools.46999.n3.nabble.com/Simple-Global-Error-tp4018697.html" target="_blank">http://drools.46999.n3.nabble.com/Simple-Global-Error-tp4018697.html</a><br>
&gt;&gt; Sent from the Drools: User forum mailing list archive at Nabble.com.<br>
&gt;&gt; _______________________________________________<br>
&gt;&gt; rules-users mailing list<br>
&gt;&gt; <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
&gt;&gt; <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
&gt;&gt;<br>
&gt;<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>
</div></div></blockquote></div><br></div>