Reputation: 193
I have this JS function:
function newJSArray() {return []}
That I am trying to return in Java using the following method:
public static NativeArray newArray() throws Exception {
return (NativeArray)invocable.invokeFunction("newJSArray");
}
But it's throwing an exception when I try to invoke this function:
Exception in thread "main" java.lang.NoSuchMethodError: ....JavaScript.newArray()Ljdk/nashorn/api/scripting/JSObject;
at ....
I want to be given a JS array specifically so I can call jsArr1.concat(jsArr2).
Upvotes: 3
Views: 1047
Reputation: 4405
Yes, all API methods return JavaScript objects as instances of jdk.nashorn.api.scripting.JSObject. You can access members of that JS array by JSObject.getSlot method.
Upvotes: 2