I recently worked with some Java collection (well know JavaFX), and I had recently a problem (a consequence of this other problem posted here). One of the JavaFX interfaces I need only accepts java.util.Map, equal to Map[_,_] in Scala.
I make a conversion with asInstanceOf, but after computation, if I want to transform my java.util.Map[_,_] to force the cast into a real Scala type safe Map[String,Double] I use in all my program, how can I do it?
I tried java.conversions._ and asInstanceOf methods without success.
//return a java.util.Map
val row: java.util.Map[_,_] = c.getTableView().getItems().get(0)
//I need a Map[String,Double] in my program
val parameters = row.toMap[String,Double]
This works for me
val javaMap : java.util.Map[_, _] = null
val scalaMap = javaMap.asScala.toMap.asInstanceOf[Map[String, Double]]
Remember to include
import scala.collection.JavaConverters._
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With