title: Creating instance from a generic class when a constructor init parameteres
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/6241513/how-to-create-instance-of-a-class-with-the-parameters-in-the-constructor-using-r">How to create instance of a class with the parameters in the constructor using reflection?</a>  </p>
  </blockquote>
  
  
  
  <p>Is it possible to happen and how? 
  I have a class <code>Gerbil</code> :</p>
  
  <pre><code>public class Gerbil {
      private int gerbilNumber;
      public Gerbil(int gn){
          this.gerbilNumber = gn;
      }
      public void hop() {
          System.out.println("It's gerbil number" + this.gerbilNumber + "and it's hopping.");
      }
  
  }
  </code></pre>
  
  <p>I have a generic class <code>TestGenerics</code>:</p>
  
  <pre><code>public class TestGenerics&lt;T&gt; {
      private Class&lt;T&gt; mClass;
  
      public TestGenerics(Class&lt;T&gt; cls){
          mClass = cls;
      }
  
      public T get(){
          try{
              return mClass.newInstance();
          }catch(Exception e){
              e.printStackTrace();
              return null;
          }
      }
  }
  </code></pre>
  
  <p>And a <code>main</code> class:</p>
  
  <pre><code>public class HelloWorld {
      public static void main(String[] args) {
          TestGenerics&lt;Gerbil&gt; g = new TestGenerics&lt;Gerbil&gt;(Gerbil.class);
          Gerbil a = g.get();
          a.hop();
      }
  }
  </code></pre>
  
  <p>The problem is that I need to provide the constructor of <code>Gerbil</code> with an integer value but don't know how (if possible). Otherwise if I leave an empty/default constructor the code is working fine, but is it possible to make an instance form a generic class when the constructor of the real class need parameters to be passed?</p>