Forcing elements of List to be converted as java.lang.Long

Attila Szegedi attila.szegedi at
Wed Nov 26 21:50:39 UTC 2014

I don't think so. As the types are erased at run time all we see is a method with signature foo(List list). I think if you tried to add two methods to a class:

    public void foo(List<Long> x) { }
    public void foo(List<Integer> x) { }

then javac would refuse to compile it saying that both have the same erasure.


On Nov 26, 2014, at 10:45 PM, Tim Fox <timvolpe at> wrote:

> Hello folks,
> I have a Java method:
> public void foo(List<Long> list) {
>  System.out.println("elem0 is " + list.get(0));
> }
> Which I call from JS with a JS array:
> This results in a ClassCastException as Nashorn converts the JS Array into a java.util.List instance which contains a java.lang.Integer element (not java.lang.Long)
> Is there any way to force Nashorn to convert the array elements as Longs not Integers?
> Thanks.

More information about the nashorn-dev mailing list