Scala 2.8.1 implicitly convert to java.util.List<java.util.Map<String, Object>>
Posted
by
Ralph
on Stack Overflow
See other posts from Stack Overflow
or by Ralph
Published on 2010-12-20T13:57:06Z
Indexed on
2010/12/21
5:31 UTC
Read the original article
Hit count: 237
I have a Scala data structure created with the following:
List(Map[String, Anyref]("a" -> someFoo, "b" -> someBar))
I would like to implicitly convert it (using scala.collection.JavaConversions
or scala.collection.JavaConverters
) to a java.util.List<java.util.Map<String, Object>>
to be passed the a Java method that expects the latter.
Is this possible?
I have already created the following method that does it, but was wondering if it can be done automatically by the compiler?
import scala.collection.JavaConversions._
def convertToJava(listOfMaps: List[Map[String, AnyRef]]):
java.util.List[java.util.Map[String, Object]] = {
asJavaList(listOfMaps.map(asJavaMap(_)))
}
© Stack Overflow or respective owner