Scala 2.10似乎更新了对Either的理解.在2.10:
scala> val a = Right(5)
a: scala.util.Right[Nothing,Int] = Right(5)
scala> for {aa: Int <- a.right} yield {aa}
<console>:9: error: type mismatch;
found : Int => Int
required: scala.util.Either[Nothing,Int] => ?
for {aa: Int <- a.right} yield {aa}
^
Run Code Online (Sandbox Code Playgroud)
在2.9.3中,以上是可以的.
scala> val a = Right(5)
a: Right[Nothing,Int] = Right(5)
scala> for {aa: Int <- a.right} yield {aa}
res0: Product with Serializable with Either[Nothing,Int] = Right(5)
Run Code Online (Sandbox Code Playgroud)
只需在2.10中删除aa的类型即可轻松修复.但我想知道为什么行为会在2.9和2.10之间发生变化.
scala ×1