title: Implementing generic interface in generic class
body: <p>I'm new to generic types, and was wondering how could I correctly implement the generic interface in a generic class, so the determination of type would be delayed to moment when I'm instantiating an object of this generic class. </p>
  
  <p>My code looks as follows:</p>
  
  <pre><code>package org.processor.interfaces;
  
  import org.filter.interfaces.IFile;
  
  public interface ProcessorResult&lt;T&gt; {
  
   public IFile getFile();
   public String getProcessorName();
   public Class&lt;? extends Processor&lt;T&gt;&gt; getProcessorClass();
   public T getResult();  
  }
  </code></pre>
  
  <p>And class which implements that interface:</p>
  
  <pre><code>package org.processor.interfaces.impl;
  import org.filter.interfaces.IFile;
  import org.processor.interfaces.Processor;
  import org.processor.interfaces.ProcessorResult;
  
  public class ProcessorResultImpl&lt;T&gt; implements ProcessorResult&lt;T&gt; {
  
  private T result;
  private String processorName;
  private IFile file;
  
  public  ProcessorResultImpl(T result) {
    this.t = result;
  }
  
  @Override
  public IFile getFile() {
    return file;
  }
  
  @Override
  public String getProcessorName() {
    return processorName;
  }
  
  @Override
  public Class&lt;? extends Processor&lt;T&gt;&gt; getProcessorClass() {
    return null;
  }
  
  @Override
  public T getResult() {
    return t;
  }
  }
  </code></pre>
  
  <p>The moment when I want to instantiate the object of this class is in method which returns ProcessorResult as follows(this is only for sake of demonstration):</p>
  
  <pre><code>import java.io.BufferedInputStream;
  import java.io.IOException;
  import java.io.InputStream;
  
  import org.filter.interfaces.IFile;
  import org.processor.interfaces.Processor;
  import org.processor.interfaces.ProcessorFilter;
  import org.processor.interfaces.ProcessorResult;
  
  public class ProcessorLineCountImpl&lt;T&gt; implements Processor&lt;T&gt; {
  
    private ProcessorFilter&lt;T&gt; processorFilter;
    private String name;
  
    public ProcessorLineCountImpl() {
  
    }
  
    public ProcessorResult&lt;T&gt; process(IFile file) {
      int count = 0;
      try (Scanner sc = new Scanner(file.openInputStream())) {
        while (sc.hasNext()) {
          String word = sc.next();
          if (word.indexOf("\\") == -1) {
            count++;
          }
        }
     return null;
  }
  return null;
  
  @Override
  public String getName() {
    return name;
  }
  
  @Override
  public void setFilter(ProcessorFilter&lt;T&gt; filter) {
     this.processorFilter = filter;
  }
  </code></pre>
  
  <p>In that case I'm getting <strong>syntax error</strong>:</p>
  
  <pre><code>Type mismatch: cannot convert from ProcessorResultImpl&lt;Long&gt; to 
  ProcessorResult&lt;T&gt;
  </code></pre>
  
  <p><strong>Questions:</strong></p>
  
  <ol>
  <li>How it could be properly done as I'm out of ideas and couldn't find any solution on the web.</li>
  <li>Is it a good approach to delay the determination of type till instantiation of object ?</li>
  </ol>
  
  <p>Thanks for any advice.</p>