Bug report: JavaScript arrays are not coerced into Java arrays when calling Java functions that expect arrays
Tal Liron
tal.liron at threecrickets.com
Tue Oct 8 05:35:28 PDT 2013
In my mind, it's acceptible if nested conversion doesn't happen: Rhino
doesn't support it, either. But one would expect that at least the
first-level of arguments would be coerced. By the way, this also works
as expected in other JVM dynamic languages: Jython, JRuby, Quercus,
LuaJ, Groovy and Clojure (though the latter both use Java arrays, so
coercion is easier: just to the array element type).
Would it be possible to support this intrinsically in mozilla_compat.js?
Or possibly add an optional flag for it in Nashorn?
This is a big deal. I have a very large application that works in Rhino
but won't work in Nashorn because of this.
On 10/08/2013 08:23 PM, Jim Laskey (Oracle) wrote:
> 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
>
More information about the nashorn-dev
mailing list