2

I have a simple code,

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

It outputs true, so I want to ask what is Type.dealias used for? When should I use it? Some code example would be helpful

I ask so because when I read spark code, ScalaReflection, it almost always use dealias before using the type

Jasper-M
  • 14,966
  • 2
  • 26
  • 37
Tom
  • 5,848
  • 12
  • 44
  • 104

1 Answers1

5

Type aliases look like

type Alias = Person

It declares a new type Alias which is the same as Person.

dealias resolves these aliases, so that typeOf[Alias].dealias will return typeOf[Person]. Because Person isn't an alias, typeOf[Person].dealias does nothing.

Also note:

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.

Alexey Romanov
  • 167,066
  • 35
  • 309
  • 487