Skip to content

Instantly share code, notes, and snippets.

@xuwei-k
Created July 1, 2011 05:20
Show Gist options
  • Save xuwei-k/1057916 to your computer and use it in GitHub Desktop.
Save xuwei-k/1057916 to your computer and use it in GitHub Desktop.
scala> sealed abstract class A
case object B extends A
case object C extends A
def hoge(xs:Map[A,Int]){ xs foreach println }
val list = Map(B -> 1 ,C -> 2)
defined class A
defined module B
defined module C
hoge: (xs: Map[A,Int])Unit
list: scala.collection.immutable.Map[Product with Serializable with A,Int] = Map(B -> 1, C -> 2)
scala> hoge(list)
<console>:27: error: type mismatch;
found : scala.collection.immutable.Map[Product with Serializable with A,Int]
required: Map[A,Int]
Note: Product with Serializable with A <: A, but trait Map is invariant in type A.
You may wish to investigate a wildcard type such as `_ <: A`. (SLS 3.2.10)
hoge(list)
^
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment