Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何比较Scala反射库类型“universe.type”和普通类型之间的公平性?_Scala_Reflection - Fatal编程技术网

如何比较Scala反射库类型“universe.type”和普通类型之间的公平性?

如何比较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

我正在练习使用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 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是列表[字符串]的子类型吗?) 热塑性弹性体