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

2014-11-27 Thread Attila Szegedi
You're right about that, Rémi. However, even in Java you can twist things with unchecked casts so that you pass a List to this method and force it into a ClassCastException, so I'm not sure if us going out of our way to inject a suitable conversion would be desired. On Nov 27, 2014, at 12:59 AM

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

2014-11-27 Thread Tim Fox
Great, that works. And it's a lot faster than manually converting the elements of the list in JS before sending it to Java :) On 27/11/14 11:24, Attila Szegedi wrote: Thinking of it, yes, there is: var asList = java.util.Arrays.asList; var LongType = Java.type("java.lang.Long

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

2014-11-27 Thread Attila Szegedi
Thinking of it, yes, there is: var asList = java.util.Arrays.asList; var LongType = Java.type("java.lang.Long[]"); then: asList(Java.to(arr, LongType)) Attila. On Nov 27, 2014, at 12:37 AM, Tim Fox wrote: > Hi Attila, > > I understand the generic type info is erased,

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

2014-11-26 Thread Remi Forax
On 11/27/2014 12:37 AM, Tim Fox wrote: Hi Attila, I understand the generic type info is erased, but my question was whether there is any way I can "force" Nashorn to convert the elements as Long rather than Integer when doing the conversion, e.g. using some special Nashorn specific syntax, e

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

2014-11-26 Thread Tim Fox
Hi Attila, I understand the generic type info is erased, but my question was whether there is any way I can "force" Nashorn to convert the elements as Long rather than Integer when doing the conversion, e.g. using some special Nashorn specific syntax, e.g. var arr = [123]; arr.forceConversio

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

2014-11-26 Thread Attila Szegedi
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 x) { } public void foo(List x) { } then javac would refuse to compile it saying that both have the same er

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

2014-11-26 Thread Tim Fox
Hello folks, I have a Java method: public void foo(List list) { System.out.println("elem0 is " + list.get(0)); } Which I call from JS with a JS array: obj.foo([123]); This results in a ClassCastException as Nashorn converts the JS Array into a java.util.List instance which contains a java.