如何从javascript / rhino调用带整数和浮点数的重载java方法?
例如,如何从javascript / rhino调用java java.awt.Color(int,int,int)构造函数? 我已经处理了下一个snipets但是不起作用:
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
答案 0 :(得分:2)
The mechanism is documented here.基本上您可以通过以下语法访问构造函数:
js> new java.awt.Color['(int,int,int)'](1,2,3); // no spaces allowed!
java.awt.Color[r=1,g=2,b=3]
或
js> java.awt.Color['(java.awt.color.ColorSpace,float[],float)']
function <init>(java.awt.color.ColorSpace,float[],float)() {
[native code, arity=0]
}