I'm working on mixed Java-Scala projects, and quite often I need to convert collections.
When I want to convert a collection of primitives, I should be writing something like this
val coll: Seq[Int] = Seq(1, 2, 3)
import scala.collection.JavaConverters._
val jColl = coll.map(v => Int.box(v)).asJava
However, I know that with both Java and Scala generic collections use boxed values, so I can safely avoid iterating with needless boxing and just write
val jColl = coll.asJava.asInstanceOf[java.util.List[java.lang.Integer]]
However, compiler won't complain if I'll make a mistake in either collection type or element type.
Is there a type-safe way of doing this avoiding extra iteration? Is there at least a way to keep checks for collection type?