Scala 2.8.1 implicitly convert to java.util.List<java.util.Map<String, Object>>
- by Ralph
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(_)))
}