Quantcast

Scala varargs to Java varargs

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Scala varargs to Java varargs

Christos KK Loverdos
Motivated by previous threads regarding varargs in two different contexts

http://article.gmane.org/gmane.comp.lang.scala.user/4599
http://article.gmane.org/gmane.comp.lang.scala.user/4588
http://article.gmane.org/gmane.comp.lang.scala.user/4519

I have hacked this conversion from Scala varargs to Java varagrs:

def g(x: Any*) =
x.asInstanceOf[scala.runtime.BoxedObjectArray].unbox(x.getClass).asInstanceOf[Array[Object]]

This can be used for instance for a java method with the following
varargs declaration:

void doStuff(Object ...args)

It smells like compiler stuff and I was wondering whether the
compiler, since it knows what it is doing, could do the transformation
itself. Just wondering as I said, I have not considered the possible
implications and/or viability of such a scheme.

Christos.

--
 __~O
 -\ <, Christos KK Loverdos
(*)/ (*) http://ckkloverdos.com
Loading...