ehr...@gmail.com
unread,Oct 27, 2013, 12:28:59 PM10/27/13You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to
I'm trying to save a reference to a Java object's method in a var, then call it later, but it fails with
Java method "run" was invoked with [object Object] as "this" value that can not be converted to Java type java.lang.Runnable.
Here's the code:
Context cx = Context.enter();
Scriptable scope = cx.initStandardObjects();
scope.put("foo", scope, Context.toObject(new Runnable() {
@Override public void run() {
System.err.println("Run");
}
}, scope));
cx.evaluateString(scope, "foo.run(); var bar = foo.run; bar();", "", 1, null);
I understand why this would fail; Rhino either didn't track Java's this when saving the reference or is having problems converting it. What's the right approach to accomplish this?