title: scala reflection, cast type with asInstanceOf
body: <p>I have</p>
  
  <pre><code>trait T
  class C extends T
  </code></pre>
  
  <p>compiled to .class files. Run scala with <code>-cp &lt;...&gt;</code> to have type <code>T</code> available. Then load class C using reflection:</p>
  
  <pre><code>val loader = ScalaClassLoader fromURLs (/* List[URL] */)
  val anyC = loader.tryToInitializeClass("C") getOrElse (/* throw something */)
  val classC = anyC.asInstanceOf[Class[T]]
  </code></pre>
  
  <p>How can I cast a <code>classC.newInstance</code> into type <code>T</code> like</p>
  
  <pre><code>val objC = classC.newInstance.asInstanceOf[T] 
  // yields java.lang.ClassCastException: C cannot be cast to T
  </code></pre>