Skip to content

Instantly share code, notes, and snippets.

@jorgeortiz85
Forked from seanparsons/gist:1656555
Created January 22, 2012 12:44
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jorgeortiz85/1656964 to your computer and use it in GitHub Desktop.
Save jorgeortiz85/1656964 to your computer and use it in GitHub Desktop.
scala.collection.JavaConversions is evil
import scala.collection.JavaConversions._
case class Foo(s: String)
val map: Map[Foo, String] =
Map(
Foo("a") -> "a",
Foo("b") -> "b")
val v = map.get("a") // should be a type error, actually returns null
@paulp
Copy link

paulp commented Mar 21, 2012

case class Foo(s: String)

object Test {
  def f1 = {
    import scala.collection.JavaConversions._
    val map: Map[Foo, String] = Map(Foo("a") -> "a", Foo("b") -> "b")
    val v = map.get("a")  // should be a type error, actually returns null
  }
  def f2 = {
    import scala.collection.JavaAsScala._
    val map: Map[Foo, String] = Map(Foo("a") -> "a", Foo("b") -> "b")
    val v = map.get("a")  // now this is a type error
  }
  def f3 = {
    import scala.collection.ScalaAsJava._
    val map: Map[Foo, String] = Map(Foo("a") -> "a", Foo("b") -> "b")
    val v = map.get("a")
  }
}

@schmmd
Copy link

schmmd commented Dec 18, 2013

JavaConverters the sane alternative?

@schmmd
Copy link

schmmd commented Dec 18, 2013

By the way, thanks for providing a hit for the search "JavaConversions is evil".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment