Bug report: JavaScript arrays are not coerced into Java arrays when calling Java functions that expect arrays
Jim Laskey (Oracle)
james.laskey at oracle.com
Tue Oct 8 05:23:31 PDT 2013
Nashorn does not coerce JS arrays implicitly. There were too many ambiguous cases to do a complete implementation (nested conversions.) In Nashorn you have to;
myInstance.myMethod(Java.to(['a', 'b', 'c'], "java.lang.String[]"));
or;
var StringArray = Java.type("java.lang.String[]");
function args(array) {
return Java.to(array, StringArray);
}
myInstance.myMethod(args(['a', 'b', 'c']));
Cheers,
-- Jim
On 2013-10-08, at 1:54 PM, Tal Liron <tal.liron at threecrickets.com> wrote:
> Lets say we have a Java class with this method:
>
> class MyClass {
> void myMethod(String[] arguments) {}
> }
>
> And in Nashorn we call it like so:
>
> myInstance.myMethod(['a', 'b', 'c'])
>
> The JavaScript array seems to be converted into a string (as "a,b,c"), and then wrapped in a Java string array as its single element before sending to Java.
>
> In Rhino, the above works as expected.
More information about the nashorn-dev
mailing list