title: In Scala Reflection, How to get generic type parameter of a concrete subclass?
body: <p>Assuming that I have a Generic superclass:</p>
  
  <pre><code>class GenericExample[T](
                           a: String,
                           b: T
                         ) {
  
    def fn(i: T): T = b
  }
  </code></pre>
  
  <p>and a concrete subclass:</p>
  
  <pre><code>case class Example(
                      a: String,
                      b: Int
                    ) extends GenericExample[Int](a, b)
  </code></pre>
  
  <p>I want to get the type parameter of function "fn" by scala reflection, so I select and filter through its members:</p>
  
  <pre><code>import ScalaReflection.universe._
  
  val baseType = typeTag[Example]
  
  val member = baseType
    .tpe
    .member(methodName: TermName)
    .asTerm
    .alternatives
    .map(_.asMethod)
    .head
  
      val paramss = member.paramss
      val actualTypess: List[List[Type]] = paramss.map {
        params =&gt;
          params.map {
            param =&gt;
              param.typeSignature
          }
      }
  </code></pre>
  
  <p>I was expecting scala to give me the correct result, which is <code>List(List(Int))</code>, instead I only got the generic <code>List(List(T))</code></p>
  
  <p>Crunching through the document I found that typeSignature is the culprit:</p>
  
  <pre><code> *  This method always returns signatures in the most generic way possible, even if the underlying symbol is obtained from an
   *  instantiation of a generic type.
  </code></pre>
  
  <p>And it suggests me to use the alternative:</p>
  
  <pre><code>def typeSignatureIn(site: Type): Type
  </code></pre>
  
  <p>However, since class Example is no longer generic, there is no way I can get site from typeTag[Example], can anyone suggest me how to get typeOf[Int] given only typeTag[Example]? Or there is no way to do it and I have to revert to Java reflection?</p>
  
  <p>Thanks a lot for your help.</p>
  
  <p><strong>UPDATE:</strong> After some quick test I found that even <em>MethodSymbol.returnType</em> doesn't work as intended, the following code:</p>
  
  <pre><code>member.returnType
  </code></pre>
  
  <p>also yield <code>T</code>, annd it can't be corrected by <em>asSeenFrom</em>, as the following code doesn't change the result:</p>
  
  <pre><code>member.returnType.asSeenFrom(baseType.tpe, baseType.tpe.typeSymbol.asClass)
  </code></pre>