1

Using TypeTag I've been able to retrieve the type information about my polymorphic type.

scala> paramInfo(List(1,2)).tpe
res18: reflect.runtime.universe.Type = List[Int]

Now I want to retrieve the Int.type, but apparently I'm unable to do so.

scala> paramInfo(List(1,2)).tpe.typeParams
res19: List[reflect.runtime.universe.Symbol] = List()

Is what I want to do possible, and if it is, how can I do that?

manub
  • 3,990
  • 2
  • 24
  • 33

2 Answers2

1

You need

paramInfo(List(1,2)).tpe match {
  case TypeRef(_, _, params) => params
}
Alexey Romanov
  • 167,066
  • 35
  • 309
  • 487
0

You can simply change the signature of paramInfo like that:

def paramInfo[T](x: List[T])(implicit tag: TypeTag[T]): TypeTag[T] = tag
Federico Pellegatta
  • 3,977
  • 1
  • 17
  • 29