How to access Java Enums from Javascript (Java 1.8)

纵饮孤独 提交于 2019-12-04 10:02:22

Nashorn introduces global function Java.type() to interact with Java classes. http://docs.oracle.com/javase/8/docs/technotes/guides/scripting/nashorn/api.html

Here is an example how you can use it

var retPolicy = Java.type("java.lang.annotation.RetentionPolicy");
print(retPolicy.RUNTIME);

Also, if you're looking the ways to migrate to Nashorn from Rhino consider following manual https://wiki.openjdk.java.net/display/Nashorn/Rhino+Migration+Guide

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