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 <[email protected]> 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.

Reply via email to