Use java class in Graal.js

*爱你&永不变心* 提交于 2019-12-10 19:47:01

问题


Using Graal.js, how can I import a java class to script within JS?

The following code works with Nashorn JJS, but does not work with Graal.js because there is no Java.type() in graal, do I need to invoke truffle at some point?

var ArrayList = Java.type("java.util.ArrayList");
var myList = new ArrayList();
myList.add("hello");
myList.add("world");
print(myList);

EDIT: I was able to get it to import java types using the --jvm paramter, which seems to indicate that it runs it on the JVM. So does this completely pas over the GraalVM and just use the JVM?


回答1:


add the --jvm arg to the JS command to run Graal.js on JVM, this will allow access to Java objects.



来源:https://stackoverflow.com/questions/47725902/use-java-class-in-graal-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!