Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#318 Scripted interface : problems with boolean in fields

open
nobody
General (151)
5
2008-06-28
2008-06-28
Anonymous
No

When implementing a Java interface with a bsh script, boolean primitive fields values are not retained for several invocations of the scripted interface methods (although they are retained for int primitive fields, or even Boolean fields).

For example, if we have a Java interface called IFoo :
package foo;
public interface IFoo {
public void run();
}

We can define a script which implement this interface:
import foo;
boolean fieldBool = false;
boolean fieldInt = 0;
Boolean fieldBool2 = false;
void run() {
fieldBool = ! fieldBool;
fieldBool2 = ! fieldBool2;
fieldInt++;
System.out.println("fieldBool: "+fieldBool);
System.out.println("fieldBool2: "+fieldBool2);
System.out.println("fieldInt: "+fieldInt);
}

An then evaluate the bsh script to get the Java interface implementation:
Interpreter bsh = new Interpreter();
bsh.eval(script);
IFoo script = bsh.getInterface(IFoo.class);

When calling script.run(), the value of fieldBool is always false, although the valule of fieldBool2 swtich from false to true as expected.

Discussion