Useful, scala universe.typeOf stores type parameters for a class.
import scala.reflect.runtime.universe._ case class X[T:TypeTag]() { val t = typeOf[T] // eg Seq[Int] Holds type parameters val clz:Class[_] = runtimeMirror(this.getClass.getClassLoader).runtimeClass(t.typeSymbol.asClass) } X[Seq[Int]]().t // Seq[Int] X[Seq[Int]]().clz // Seq :-(
Java ParameterizedType contains the same information that has not been erased. How to convert scala type to Java ParameterizedType?
import scala.reflect.runtime.universe._ case class X[T:TypeTag]() { val clz:Class[_] = runtimeMirror(this.getClass.getClassLoader).runtimeClass(typeOf[T].typeSymbol.asClass) }
source share