diff options
author | Martin Odersky <odersky@gmail.com> | 2014-12-21 12:38:16 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2014-12-21 12:38:33 +0100 |
commit | f98ce3f42a77802fc98eb0f12636efc1f25c2d1b (patch) | |
tree | 451c5d72a40acfa4ee5c75f8ebcf033964d3e887 /src/dotty/runtime/Arrays.scala | |
parent | 3648ea82d5150d0685bbde3991abcfe007c38987 (diff) | |
download | dotty-f98ce3f42a77802fc98eb0f12636efc1f25c2d1b.tar.gz dotty-f98ce3f42a77802fc98eb0f12636efc1f25c2d1b.tar.bz2 dotty-f98ce3f42a77802fc98eb0f12636efc1f25c2d1b.zip |
Fix passing : _* arguments to Java methods
Arguments of the form (xs: _*) which are passed to
Java methods need to be converted to arrays, not sequences.
Diffstat (limited to 'src/dotty/runtime/Arrays.scala')
-rw-r--r-- | src/dotty/runtime/Arrays.scala | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/dotty/runtime/Arrays.scala b/src/dotty/runtime/Arrays.scala index e7f819df8..5767991e5 100644 --- a/src/dotty/runtime/Arrays.scala +++ b/src/dotty/runtime/Arrays.scala @@ -2,7 +2,7 @@ package dotty.runtime import scala.reflect.ClassTag -/** All but the first operation should be short-circuited and implemented specially by +/** All but the first two operations should be short-circuited and implemented specially by * the backend. */ object Arrays { @@ -12,7 +12,14 @@ object Arrays { */ def newGenericArray[T](length: Int)(implicit tag: ClassTag[T]): Array[T] = tag.newArray(length) - + + /** Convert a sequence to a Java array with element type given by `clazz`. */ + def seqToArray[T](xs: Seq[T], clazz: Class[_]): Array[T] = { + val arr = java.lang.reflect.Array.newInstance(clazz, xs.length).asInstanceOf[Array[T]] + xs.copyToArray(arr) + arr + } + /** Create an array of type T. T must be of form Array[E], with * E being a reference type. */ |