title: Is there a way to find the type of a template (generic) parameter in Java?
body: <p>I'm trying to do something like this in Java:</p>
  
  <pre><code>public static &lt;T&gt; T foo() {
    return (T) bar(T);
  }
  
  public static Object bar(Class&lt;?&gt; klaz) {
    return klaz.newInstance();
  }
  </code></pre>
  
  <p>But the code doesn't compile since I can't substitute <i>T</i> for a <i>Class&lt;?></i>.<br>
  With a concrete class, I can call <i>bar</i> like:</p>
  
  <pre><code>bar(ConcreteClass.class);
  </code></pre>
  
  <p>But the same does not work for <i>T</i>. i.e. there's no such thing as <i>T.class</i>  </p>
  
  <p>In C#, <i>typeof</i> works for both concrete and template types. So, the call to bar would've been:</p>
  
  <pre><code>bar(typeof(T));
  </code></pre>
  
  <p>But I haven't been able to find anything similar in Java.  </p>
  
  <p>Am I missing something, or does Java not have a way of getting the type of a template parameter? And if Java doesn't have the facility, are there any workarounds?</p>