我遇到了一个奇怪的问题,在Scala 2.10.0 Milestone 4中反射,我无法环绕我的头。首先对于工作方式的东西,我会期望:Scala中的类型相等2.10反射API
scala> import scala.reflect.runtime.universe._
import scala.reflect.runtime.universe._
scala> trait A[X]; trait B[Y] extends A[Y]
defined trait A
defined trait B
scala> typeOf[B[String]].parents
res0: List[reflect.runtime.universe.Type] = List(java.lang.Object, A[String])
scala> typeOf[B[String]].parents contains typeOf[A[String]]
res1: Boolean = true
同样(在同一个会话):
scala> trait D; trait E extends A[D]
defined trait D
defined trait E
scala> typeOf[E].parents
res2: List[reflect.runtime.universe.Type] = List(java.lang.Object, A[D])
scala> typeOf[E].parents contains typeOf[A[D]]
res3: Boolean = true
没有这里的惊喜:我可以要求一个类型的父母,并得到什么我预计。现在我基本结合上面的两个例子:
scala> trait F extends A[String]
defined trait F
scala> typeOf[F].parents
res4: List[reflect.runtime.universe.Type] = List(java.lang.Object, A[String])
scala> typeOf[F].parents contains typeOf[A[String]]
res5: Boolean = false
我不明白这可能是错误的。同样的事情发生,如果我有F
延伸A[Seq[D]]
,A[Int]
等等。我错过了什么概括会使这种行为有意义?
我刚刚证实,这是固定在2.10.0-M5。 –