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