score:0

Accepted answer

Use _.typeSignature.typeArgs.head, because String is a type argument of String*, not its typeSymbol.

score:0

Your parameter x is type of String*. That is what you get by calling:

_.typeSignature.typeSymbol

but String* is intrepreted as Seq[String] (as we all know). Thus calling:

_.typeSignature.typeArgs

will get you your type arguments, i.e. your desired String. Btw. if you want to prove that String* is Seq just call:

_.typeSignature.erasure

So your modified code should look like (omitting class C):

val c = C()
val r = runtimeMirror(getClass.getClassLoader).reflect(c)
val x = r.symbol.typeSignature.member(newTermName("f"))
val params = x.asMethod.paramss.head.map {
  _.typeSignature.typeArgs
}
for (param <- params) {
  println(param)
}

it will print List(String).

Enjoy


Related Query

More Query from same tag