title: Instantiate type-parametrized class at runtime with default constructor
body: <p>I want to instantiate a new object with the following classes:</p>
  
  <pre><code>class Test[T : ClassTag](val value : T) extends Serializable
  
  private object Test {
    private var testClass : Class[_] = _
  
    def setTestClass(test : Class[_]) : Unit = {
      testClass = test
    }
  
    def apply[T : ClassTag](value : T) : Test[T] = {
      testClass.getConstructors()(0).newInstance(value).asInstanceOf[Test[T]]
    }
  }
  
  class Subtest[T : ClassTag](
      override val value : T, 
      val additional : Integer
  ) extends Test[T](value)
  </code></pre>
  
  <p>I set the test-class with <code>setTestClass</code> somewhere, that has been loaded with <code>Class.forName</code> from a string. Let say it is <code>"Subtest"</code>. I wish to instantiate a new <code>Subtest[String]</code> with - for example the following code:</p>
  
  <pre><code>Test("my random string") // It should return a new Subtest[String]
  </code></pre>
  
  <p>The problem is that <code>newInstance</code> throws <code>java.lang.IllegalArgumentException: wrong number of arguments</code>. I've checked the <code>parameterTypes</code> of the <code>Constructor</code>, and there are two parameter types:</p>
  
  <ul>
  <li>class java.lang.Object</li>
  <li>interface scala.reflect.ClassTag</li>
  </ul>
  
  <p>Okay. How to supply the ClassTag? What is the problem here?
  Is there a better approach, workaround for this?</p>