Skip to content

new Interface() does not work in Nashorn compatibility mode #542

@davidpcaldwell

Description

@davidpcaldwell

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.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions