Global "variables" aren't plain old Java variables; they are kept in a wrapped map. Functions are passed to a Java compiler "as is", with only the import list added to the compilation unit.

So you can use a global in a DRL function
The second option brings us back to square 1: you can't use a global... But a public static from any application class might be used - imports are available in functions. Which, after all, could be used for your 'x' in the first place.

-W



 

On 21 July 2011 00:13, bob.breitling <bob.breitling@rrd.com> wrote:
I have a global defined and I am trying to use it from a function.  When my
rule gets loaded into my knowledge base, I always get an error complaining
about the global not being resolved.

---- simplified snippet ----

global int x;

function void foo(int n) {
   x = n;
}

------------------------------

I get this kind of error "Function Compilation error: foo (line:20) x can
not resolved".

Should this work?

TIA,

Bob

--
View this message in context: http://drools.46999.n3.nabble.com/Globals-from-functions-tp3186882p3186882.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