title: Making a generic function and using TypeOf on it
body: <p>I have a mother trait 'Contract' that is extended by a number of case classes, 'scale' being one of them. I am trying to make a generic function such that it takes an object of one of those case classes and does some action on the basis of what kind of object it is. This is the partial code:</p>
  
  <pre><code> def getType[T: TypeTag](obj: T) = typeOf[T]
  
   def makeXMLElem[T &lt;: Contract](contract: T): String = {
        println(getType(contract))
        val symb = getType(contract).declaration(newTermName(name)).asTerm
        val instanceMirror = runtimeMirror(contract.getClass.getClassLoader).reflect(contract)
        val symbMirror = instanceMirror.reflectField(symb)
        val symbValue = symbMirror.get
        .......
  </code></pre>
  
  <p>Now, I try to pass 'scale' and check its type. The getType function returns its type to be 'Contract' rather than 'scale'. As you can understand, I am trying to access the parameters of the case class 'scale' using the statement:</p>
  
  <pre><code>val symb = getType(contract).declaration(newTermName(name)).asTerm
  </code></pre>
  
  <p>case class 'scale' has the following signature:</p>
  
  <pre><code>case class scale(amount:Int, currency:String)
  </code></pre>
  
  <p>Since, the type itself is being extracted wrongly, the value 'symb' does not give any value and I get the following runtime error:</p>
  
  <pre><code>Caused by: scala.ScalaReflectionException: &lt;none&gt; is not a term
  </code></pre>
  
  <p>How can I make the function makeXMLElem more generic without the loss of information regarding the signature of 'scale' or any class that extends 'Contract' for that matter?</p>