Can we define a method name alias when using a Java object/class form Nashorn?

Paulo Lopes pmlopes at
Thu Mar 9 12:20:03 UTC 2017


For the Vert.x project I've created a simple Promise implementation as
available in a Browser.

I've then played with babel to transpile the ES7 async - await to Promises
and I must say that it works fine under Nashorn.

Now my concern is that since this code is always in the hot-path I'd like
to translate it to Java so it could be executed/jitted faster, however the
Promise API has a small issue with that, it defines a method named: "catch"

This is forbidden name for a java method since according to the JLS "catch"
is a reserved word and Java is way more strict than JS. My question is, now:

Do I need to implement this using the JSObject interface where I can react
to a "getMember" to return a Function and then handle it on the "call"
method, or is there some "magic" where I can keep it all under a single
Java object and make an alias?

I expect that if I implement the JSObject that I'll start making to many
small lived objects and the performance improvements would be lost with the
GC pressure...

More information about the nashorn-dev mailing list