title: Generics factory in Java
body: <p>Can anybody post the Java version of this VB.NET code?</p>
  
  <pre><code>    Public Function FetchDoc(Of T As {New, IRepoDocument})(ByVal docId As String) As IRepoDocument Implements IDocRepository.FetchDoc
  
          Dim repoDoc As New T
  
          //some code to init repoDoc
  
          Return repoDoc
  
      End Function
  </code></pre>
  
  <p>This function accepts and create a instance of any class implementing <code>IRepoDocument</code> and has a no-argument constructor.</p>
  
  <p>The only way I found is:</p>
  
  <pre><code>public &lt;T extends IRepoDocument&gt; IRepoDocument FetchDoc(String idDoc, Class&lt;T&gt; clazz)
      throws InstantiationException, IllegalAccessException 
  {
    return clazz.newInstance();
  }
  </code></pre>
  
  <p>But I want to suppress <code>Class&lt;T&gt; clazz</code> as input parameter.</p>