title: Cannot Instantiate the Type T
body: <p>I have a class that looks like this...</p>
  
  <pre><code>public class LegionInputFormat
          extends FileInputFormat&lt;NullWritable, LegionRecord&gt; {
  
      @Override
      public RecordReader&lt;NullWritable, LegionRecord&gt;
              createRecordReader(InputSplit split, TaskAttemptContext context) {
  
          /* Skipped code for getting recordDelimiterBytes */
  
          return new LegionRecordReader(recordDelimiterBytes);
      }
  }
  </code></pre>
  
  <p>I'd like to use a generic type so it could return any type of RecordReader specified by the user, like so:</p>
  
  <pre><code>public class LegionInputFormat&lt;T extends RecordReader&lt;NullWritable, LegionRecord&gt;&gt;
          extends FileInputFormat&lt;NullWritable, LegionRecord&gt; {
  
      @Override
      public RecordReader&lt;NullWritable, LegionRecord&gt;
              createRecordReader(InputSplit split, TaskAttemptContext context) {
  
          /* Skipped code for getting recordDelimiterBytes */
  
          return new T(recordDelimiterBytes);
      }
  }
  </code></pre>
  
  <p>As the post title suggests, I'm being told I "cannot instantiate the Type T." From other Stack Exchange posts, I've gathered that this is not possible due to something with how generics work. What I've not been able to gather is an intuitive explanation of why that's the case. I learn best by understanding, so that would be really helpful if somebody can offer it.</p>
  
  <p>I'm also interested in the best practice for accomplishing what I'm looking to do here. Should the constructor for <code>LegionInputFormat</code> accept a <code>RecordReader</code> class, store that, and then reference it later to create a new instance? Or is there a better solution?</p>
  
  <p>(Additional background - context here is Hadoop, but I doubt it matters. I'm a fairly accomplished Data Scientist, but I'm pretty new to Java.)</p>