Scala 反射 API Type.dealias 有什么作用?

What does scala reflection API Type.dealias do?

我有一个简单的代码,

case class Person(name: String, age:Int)
import scala.reflect.runtime.universe._
val t1 = typeOf[Person]
val t2 = t1.dealias
println(t1 == t2)

输出的是true,请问Type.dealias是做什么用的?我应该什么时候使用它?一些代码示例会有所帮助

我这么问是因为当我阅读 spark 代码 ScalaReflection 时,它几乎总是在使用类型

之前使用 dealias

类型别名类似于

type Alias = Person

它声明了一个新类型 Alias,与 Person 相同。

dealias 解析这些别名,因此 typeOf[Alias].dealias 将 return typeOf[Person]。因为 Person 不是别名,所以 typeOf[Person].dealias 什么都不做。

另请注意:

Type Equality can be checked with =:=. It's important to note that == should not be used to compare types for equality-- == can't check for type equality in the presence of type aliases, while =:= can.