title: Runtime Generic Type Java
body: <p>Suppose I have:</p>
  
  <pre><code>ClassA extends SuperClass{ ...}
  ClassB extends SuperClass{ ... }
  </code></pre>
  
  <p>also <code>ClassX&lt;T extends SuperClass&gt; { ... }</code></p>
  
  <p>Now, during runtime I have come across an object which I know should be one of ClassA or ClassB. And I want to create an instance of ClassX based on that. How can I do that?</p>
  
  <p>I have tried: </p>
  
  <pre><code>Class&lt;?&gt; className = object.getClass();
  Class&lt;className&gt; objectx = ...
  </code></pre>
  
  <p>which does not work.</p>
  
  <p>Thanks in advance!</p>