import scala.collection.JavaConversions._
val j: java.util.Map[String, String] = Map("a" -> "b")
print (j)
How does it work? In other words I am dying to know how import of some library (JavaConversions
here) can help in making some conversions. After all, I didn't call any conversion function.
How does it work?
You can always see how implicits are resolved using
reify
So with implicits brought by the import of
scala.jdk.CollectionConverters._
the lineis transformed into
This rewriting (implicit resolution) occurs at compile time using static types, but methods
.MapHasAsJava(..)
,.asJava
are called as always at runtime using dynamic dispatch.Similarly, with former version of Scala
means that the line
is transformed into