title: Getting class instance from generic type in Java
body: <p>I've a method in which I'm passing a generic argument. To execute one required method I need the class instance of the same. How can I get it.
  There is a workaround which I'm using but I want to know how can we get the <code>Class</code> instance.</p>
  
  <p>The snippet I'm using is:</p>
  
  <pre><code>public &lt;T&gt; T readModelWithId(Class&lt;T&gt; c, Serializable pk) {
      // Some code here.
      T t = (T)session.get(c, pk);
      // Some code here.
      return t;
  }
  </code></pre>
  
  <p>The problem is that I don't want to pass the <code>Class</code> instance in this method as it is same as the return type <code>T</code> which is of generic type.</p>