I would like to be able to perform the following, but it fails in the call to useMap. How can I perform this conversion?
scala> import scala.collection.JavaConversions._
import scala.collection.JavaConversions._
scala> import scala.collection.JavaConverters._
import scala.collection.JavaConverters._
scala> def useMap(m: java.util.Map[java.lang.Integer, java.lang.Float]) = m
useMap: (m: java.util.Map[Integer,Float])java.util.Map[Integer,Float]
scala> val v: Map[Int, Float] = Map()
v: Map[Int,Float] = Map()
scala> useMap(v)
<console>:10: error: type mismatch;
found : scala.collection.immutable.Map[Int,scala.Float]
required: java.util.Map[Integer,java.lang.Float]
useMap(v)
^
It seems to work with Map[String, String], but not Map[Int, Float].
question from:
https://stackoverflow.com/questions/16583265/how-can-i-convert-scala-map-to-java-map-with-scala-float-to-java-float-k-v-conve 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…