我希望能够执行以下操作,但在调用 useMap 时失败。如何执行此转换?
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)
^
它似乎适用于 Map[String, String],但不适用于 Map[Int, Float]。