Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extending Java classes from JavaScript code #32

Closed
madoar opened this issue Jul 24, 2018 · 3 comments
Closed

Extending Java classes from JavaScript code #32

madoar opened this issue Jul 24, 2018 · 3 comments

Comments

@madoar
Copy link

madoar commented Jul 24, 2018

I'm interested to learn how to extend Java classes/interfaces with graal.js.
I know of the "nashorn way" to extend Java classes/interfaces, which is using either the new operator or to use Java.extend, but I'm not sure how this can be achieved in graal.js without the nashorn compatibility mode?

@wirthi
Copy link
Member

wirthi commented Jul 25, 2018

Hi madoar,

thanks for your question. As of RC5 (published early August), Java.extend will be available by default, outside Nashorn compatibility mode.

The syntax extension around new Interface|AbstractClass(fn|obj) is still only available in Nashorn compatibility mode. Users writing new code should be able to use Java.extend for all cases; we will continue to monitor this.

Best,
Christian

@madoar
Copy link
Author

madoar commented Jul 25, 2018

Thank you for the information!

This leads me to another question.
With Graal.js supporting the "new" class syntax of ECMAScript 6, I'm asking myself if it's planned to support this syntax for the extension of Java classes.

In my eyes, it would be ideal if it's possible to extend a Java class AbstractClass by using:

class ConcreteClass extends AbstractClass {
   ...
}

or

class ConcreteClass extends Java.type("AbstractClass") {
   ...
}

@woess
Copy link
Member

woess commented Aug 2, 2018

@madoar I like the idea of using the class syntax, but I have some reservations about mixing JS and Java class semantics. It raises some questions about how class evaluation has to be changed to support this, and you'll only really know at runtime if you're extending a Java class.

We'll consider it in the future, but for the time being we'll only support the "Nashorn way" (that comes from a time when JS didn't have classes yet).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants