I\'m interested in creating a TypeTag manually (since 2.10M5):
object X {
import reflect.runtime.universe._
def tt[A : TypeTag](a: A) = typeTag[A] // how
The function definition
def tt[A : TypeTag](a: A) = typeTag[A]
is just another way of writing
def tt(a: A)(implicit tag: TypeTag[A]) = tag
which means that the instance of a tag is being created implicitly by the compiler. The reasoning behind this is that Scala compiler solves the JVM's type erasure problem by hardcoding the otherwise erased type information.
In case you're not familiar with type erasure issue, it is that JVM doesn't store the type parameters information, for instance a type Seq[Set[Int]]
would be seen simply as Seq[_]
by the JVM and there would be no way for you to find out the missing type information with reflection.