【发布时间】:2013-11-01 18:23:10
【问题描述】:
我正在练习使用 Scala 反射功能,我得到了这个结果:
res46: reflect.runtime.universe.Type = scala.List[String]
如何测试结果值是否代表List[String]?
换句话说,如何测试universe.Type是否代表指定的普通Scala类型?
【问题讨论】:
标签: scala reflection
我正在练习使用 Scala 反射功能,我得到了这个结果:
res46: reflect.runtime.universe.Type = scala.List[String]
如何测试结果值是否代表List[String]?
换句话说,如何测试universe.Type是否代表指定的普通Scala类型?
【问题讨论】:
标签: scala reflection
import scala.reflect.runtime.universe._
val tpe: Type = ???
//type equivalence test (is tpe exactly List[String]?)
tpe =:= typeOf[List[String]]
//type conformance test (is tpe a subtype of List[String]?)
tpe <:< typeOf[List[String]]
【讨论】: