Created
July 1, 2011 05:20
-
-
Save xuwei-k/1057916 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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