java 8 - How do I pass a class to a method in Nashorn? -
one of our scripts has following line, calling method in ant provider:
var provider = resource.as(org.apache.tools.ant.types.resources.fileprovider);
since updating java 8, fails error:
java.lang.classcastexception: cannot cast jdk.internal.dynalink.beans.staticclass java.lang.class @ sun.invoke.util.valueconversions.newclasscastexception(valueconversions.java:461) @ sun.invoke.util.valueconversions.castreference(valueconversions.java:456) @ jdk.nashorn.internal.scripts.script$\^eval\_.getfilehack(<eval>:131) @ jdk.nashorn.internal.scripts.script$\^eval\_.runscript(<eval>:207)
i'm trying figure out has changed nashorn docs, isn't particularly clear. following change use see in documented examples gives same error:
var provider = resource.as(java.type("org.apache.tools.ant.types.resources.fileprovider"));
how convert staticclass java class pass in here?
use .class
:
var provider = resource.as(org.apache.tools.ant.types.resources.fileprovider.class);
or
var provider = resource.as(java.type("org.apache.tools.ant.types.resources.fileprovider").class);
just in java :-)
Comments
Post a Comment