I'm trying to extend a Java class in a JavaScript project using ES4X/Graal. The class that I want to extend, has methods with overloeaded parameters that I need to override. I know that you can call a specific Java method by using the square brackets notation and specifying the type (example below), but, apparently, there's no way to specify the parameter types when overriding, per the Graal/Oracle/Nashorn documentation. So if you have the following:
package com.mycomp;
class A {
public void method(String parameter) {...}
public void method(int parameter) {...}
}
you can call either method in JavaScript like so:
var a = Java.type("com.mycomp.A");
a["method(String)"]("Some string parameter")
a["method(int)"](42)
a.method(stringOrIntParam)
However, when extending, you can only do the following:
var ClassAFromJava = Java.type("com.mycom.A");
var MyJavaScriptClassA = Java.extend(ClassAFromJava, {
method: function(stringOrIntParam) {...}
}
I want to be able to extend only one of the method(...)
, um, methods. And what about overloaded methods with different return types?
Thanks!