mercredi 12 août 2020

In Scala, how to determine if a Class is a subclass of a Parent Class or Trait?

In Scala, how can we determine if a Class is a subclass of a Parent Class or a Trait? For example:

trait MyTrait
class MyParentClass()

case class MySubClass() extends MyParentClass with MyTrait

Is it possible to identify if class such as MySubClass extends from MyParentClass or MyTrait without instantiating an object and through reflection APIs? Given an unknown generic type T, I am interested in having it match a case if T extends a particular parent class or a trait.





Aucun commentaire:

Enregistrer un commentaire