假设我有一个Type
实例列表(引用类!),以及一个未知类型的运行时对象。查找对象是子类型的/类型。
import reflect.runtime.universe._
// obj _required_ to be of type Any, no compile time type available
def find(tps: List[Type], obj: Any): Option[Type] = ???
这样
sealed trait Gender
case object Male extends Gender
case object Female extends Gender
case object Other extends Gender
val tps = List(typeOf[Male.type], typeOf[Female.type], typeOf[Other.type])
assert(find(tps, Other).get =:= typeOf[Other.type])