You need to specify ClassManifest
for the array type, T
This is accessible by a companion object (see Note) for ClassManifest
. So:
itr.toArray(ClassManifest$.MODULE$.fromClass(T.class));
In this example, T
is a real type (not a type parameter). For example, if itr
was Seq[String]
, you should use this:
itr.toArray(ClassManifest$.MODULE$.fromClass(String.class));
Since scala Map
is actually a collection of tuples, you should use this:
map.toArray(ClassManifest$.MODULE$.fromClass(Tuple2.class));
Of course, this gives you Tuple2[]
, not Tuple2<K,V>[]
for the keys and value types K
and V
respectively. Since you are in Java-land, you can use the original type
<h / "> Note : access to a companion object from Java.
A companion object of type M
is accessible by accessing the static field M$.MODULE$
source share