Skip to content

Instantly share code, notes, and snippets.

@xeno-by
Created February 2, 2013 07:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save xeno-by/4696431 to your computer and use it in GitHub Desktop.
Save xeno-by/4696431 to your computer and use it in GitHub Desktop.
import scala.reflect.runtime.universe._
import scala.reflect.api.{TypeCreator, Universe}
object Test extends App {
def foo[T: TypeTag] = TypeTag(typeTag[T].mirror, new TypeCreator {
override def apply[U <: Universe with Singleton](m: scala.reflect.api.Mirror[U]): U # Type = {
typeTag[T].in(m).tpe match {
case TypeRef(_, _, argHead :: Nil) => argHead.asInstanceOf[U#Type]
}
}
})
println(foo[List[Int]])
}
08:23 ~/Projects/Kepler_snippet00/sandbox (topic/snippet00)$ scalac Test.scala && scala Test
TypeTag[Int]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment