lundi 20 avril 2015

Inferred List Type with Either and Option

In Scala 2.11.6, putting an Either and an Option into a List results in the inferred type, List[Object]:

scala> val e: Either[String, Int] = Right(100)
e: Either[String,Int] = Right(100)

scala> val o: Option[Int] = None
o: Option[Int] = None

scala> List(e, o)
res0: List[Object] = List(Right(100), None)

Either and Option both extend AnyRef, so why isn't it a List[AnyRef]?

Why doesn't AnyRef show up as the Least Upper Bound?

Also, I was expecting a List[Any]. Why does List[Object] show up?

Aucun commentaire:

Enregistrer un commentaire