如何比较Scala反射库类型“universe.type”和普通类型之间的公平性?
我正在练习使用Scala反射功能,我得到了以下结果:如何比较Scala反射库类型“universe.type”和普通类型之间的公平性?,scala,reflection,Scala,Reflection,我正在练习使用Scala反射功能,我得到了以下结果: res46: reflect.runtime.universe.Type = scala.List[String] 如何测试结果值,查看它是否表示列表[字符串] 换句话说,如何测试universe.Type是否表示指定的普通Scala类型?导入Scala.reflect.runtime.universe_ import scala.reflect.runtime.universe._ val tpe: Type = ??? //type
res46: reflect.runtime.universe.Type = scala.List[String]
如何测试结果值,查看它是否表示列表[字符串]
换句话说,如何测试universe.Type
是否表示指定的普通Scala类型?导入Scala.reflect.runtime.universe_
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]]
val tpe:类型=???
//类型等效性测试(tpe是否准确列出[字符串]?)
tpe=:=typeOf[List[String]]
//类型一致性测试(tpe是列表[字符串]的子类型吗?)
热塑性弹性体