scala> class Generic[T](arg: T)defined class Genericscala> typeOf[Generic[Int]]res37: reflect.runtime.universe.Type = Generic[Int] // fine, so a full type info is here
scala> typeOf[Generic[Int]].declaration(nme.CONSTRUCTOR).asMethod.paramss(0).map(_.asTerm.typeSignature)res38: List[reflect.runtime.universe.Type] = List(T)T? Huh. Looks like we get a formal type here, not the actual. So how to get the actual type Int here?I know I can grab the actual type args for the whole class type by using match { case TypeRef(_, _, args) => args }.Then possibly use the "substituteTypes" method, but I didn't figure it out how to make it all fit together.Can you give me a hint how to get actual unerased types of arguments to any method/constructor obtained by reflection?Thanks,Piotr
--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-user+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-user+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Use typeSignatureIn instead of typeSignature - that should help.
scala> val tp = typeOf[Generic[Int]]
tp: reflect.runtime.universe.Type = Generic[Int]
scala> val constructor = tp.declaration(termNames.CONSTRUCTOR).asMethod
constructor: reflect.runtime.universe.MethodSymbol = constructor Generic
scala> val typeSig = constructor.typeSignatureIn(tp)
typeSig: reflect.runtime.universe.Type = (arg: Int)Generic[Int]
Type#declaration just gives you back a Symbol representing a method. You would get the same symbol back from typeOf[Generic[_].decl(...).