This is the poster child example for the dangers of import JavaConversions._
:
scala> val m = Map(1 -> "one")
m: scala.collection.immutable.Map[Int,String] = Map(1 -> one)
scala> m.contains(1)
res0: Boolean = true
scala> m.contains("")
:9: error: type mismatch;
found : String("")
required: Int
m.contains("")
^
scala> import collection.JavaConversions._
import collection.JavaConversions._
scala> m.contains("")
res2: Boolean = false
Instead of issuing a type error, the compiler converts the Scala Map
to to a java.util.Map
, which has a looser signature that accepts Object
.