You can do this quite easily in 2.10 (M4 or later):
import scala.reflect.runtime.universe._ def superTypes(t: Type): Set[Type] = (t.parents ++ t.parents.flatMap(superTypes)).toSet def allTypes[A](a: A)(implicit tag: TypeTag[A]) = superTypes(tag.tpe) + tag.tpe
Which gives us the following:
scala> allTypes(1).foreach(println) AnyVal Any NotNull Int scala> allTypes("1").foreach(println) String Any Object Comparable[String] CharSequence java.io.Serializable scala> allTypes(List("1")).foreach(println) scala.collection.LinearSeq[String] scala.collection.GenSeq[String] scala.collection.IterableLike[String,List[String]] scala.collection.GenIterable[String] scala.collection.GenTraversableLike[String,Iterable[String]] ...
You will have a much harder time to do something like this pre-2.10.
source share