我当前的 JavaScript 如下所示:
o.timer(function (){
//Call from Java
print("Hello World");
}).start(1000);
在 Java 端收到一个jdk.nashorn.internal.runtime.ScriptFunction女巫,我试图与之通话
ScriptFunction callback = ...
callback.getBoundInvokeHandle(MethodType.methodType(Object.class)).invoke();
但它抛出了这个:
java.lang.IllegalStateException: no current global instance
at jdk.nashorn.internal.objects.Global.instance(Global.java:474)
at jdk.nashorn.internal.objects.ScriptFunctionImpl.<init>(ScriptFunctionImpl.java:145)
at jdk.nashorn.internal.scripts.Script$\^eval\_._L3(<eval>:6)
at demo.Mainr$1.run(Main.java:38)
at java.util.TimerThread.mainLoop(Timer.java:555)
at java.util.TimerThread.run(Timer.java:505)
我怎样才能调用这个函数?