Question

how I can invoke an overloaded java method with integer and float from javascript/rhino?

for example, how can I invoke from javascript/rhino the java java.awt.Color(int,int,int) constructor? I have dealt with the next snipets but does not work:

var Integer = java.lang.Integer;

var color = new java.awt.Color(12,58,92); // it invokes java.awt.Color(float,float,float) and throws Wrapped java.lang.IllegalArgumentException: Color parameter outside of expected range: Red Green Blue.
var color = new java.awt.Color(new Integer(12), new Integer(58), new Integer(92) // it invokes java.awt.Color(float,float,float) and throws exception
var color = new Color(Integer.valueOf(12),Integer.valueOf(200),Integer.valueOf(80)); // it invokes java.awt.Color(float,float,float) and throws exception
Was it helpful?

Solution

The mechanism is documented here. Basically you can access the constructor by the following syntax:

js> new java.awt.Color['(int,int,int)'](1,2,3); // no spaces allowed!
java.awt.Color[r=1,g=2,b=3]

or

js> java.awt.Color['(java.awt.color.ColorSpace,float[],float)']
function <init>(java.awt.color.ColorSpace,float[],float)() {
        [native code, arity=0]
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top