new Interface() does not work in Nashorn compatibility mode · Issue #542 · oracle/graal (original) (raw)
It is documented to work here: "Nashorn compatibility mode ... "Functionality only available under this flag includes: ... new Interface|AbstractClass(fn|obj)
." Java.extend
does not work either.
However, it does not work with 1.0.0-rc3.
Command:
vm/Contents/Home/bin/js --js.nashorn-compat=true --jvm bug/extend.js
Source (bug/extend.js
):
var System = Java.type("java.lang.System");
System.err.println(typeof(Java.extend));
if (Java.extend) {
var runnable = new (Java.extend(
Java.type("java.lang.Runnable"),
{
run: function() {
System.err.println("Running.")
}
}
))();
runnable.run();
} else {
System.err.println("Java.extend not found.");
}
var Runnable = Java.type("java.lang.Runnable");
try {
var again = new Runnable({
run: function() {
System.err.println("Running again.");
}
});
again.run();
} catch (e) {
System.err.println("Error using new Runnable()");
}
Result:
undefined
Java.extend not found.
Error using new Runnable()
Expected result (jjs
):
function
Running.
Running again.