title: Unknown / Wildcard (?) Generic type in method call
body: <p>I have the following two interfaces:</p>
  
  <pre><code>public interface ParsedFile&lt;K, V extends FileEntry&gt;{...}
  </code></pre>
  
  <p>And</p>
  
  <pre><code>public interface MetricsProduces&lt;K, V extends FileEntry&gt;{
      Metrics generateMetrics(ParsedFile&lt;K, V&gt; parsedFile);
  }
  </code></pre>
  
  <p>I have the following generic code the should be able to handle any FileEntry types:</p>
  
  <pre><code>Option&lt;FileDefinition&gt; option = fileContainer.matchFile(file);
  if (option.isSome){
    FileDefinition fileDef = option.some();
    ParsedFileFactory&lt;?&gt; factory = filterDefinition.getFactory();
    ParsedFile&lt;?, ?&gt; parsedFile = factory.parseFile(file);
    MetricsProducer&lt;?, ?&gt; metricsProducer = fileDefinition.getMetricsProducer();
    Metrics metrics = metricsProducer.generateMetrics(parsedFile);
  }
  </code></pre>
  
  <p>This block of code is designed to be able to parse any type of file given the appropriate FileDefinition. However I am getting the following compile-time error:</p>
  
  <pre><code>The method generateMetrics(ParsedFile&lt;capture#5-of ?, capture#6-of ? extends FileEntry&gt;) 
  in the type MetricsProducer&lt;capture#5-of ?, cature#6-of ? extends FileEntry&gt; 
  is not applicable for the arguments 
  (ParsedFile&lt;capture#7 of ?, capture#8-of ? extends FileEntry&gt;)
  </code></pre>
  
  <p>Is there a way to let the compiler know that the "?" type of ParsedFile is the same as the "?" type of MetricsProducer? Is there another option for doing this?</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>I have fixed (as noted this causes a cast warning) the code as follows but was wondering if there is a better option:</p>
  
  <pre><code>public interface MetricsProduces&lt;K, V extends FileEntry&gt;{
      Metrics generateMetrics(ParsedFile&lt;?, ? extends FileEntry&gt; parsedFile);
  }
  
  public class TasksMetricsProduces&lt;String, TaskFileEntry&gt; implements MetricsProduces&lt;...&gt;{
  
      public Metrics generateMetrics(ParsedFile&lt;?, ? extends FileEntry&gt; parsedFile){
           ParsedFile&lt;String, TaskFileEntry&gt; parsedFile2 = (ParsedFile&lt;String, TaskFileEntry&gt;)parsedFile;
      }
  }
  </code></pre>
  
  <p><strong>Edit 2: per comments / suggestions</strong></p>
  
  <p>So I found that if I lock down the types earlier I can do the following:</p>
  
  <pre><code>public interface FileDefinition&lt;K, V extends FileEntry, T extends ParsedFile&lt;K, V&gt;&gt;{...
  
  
  public void myMethod(){
       for (FileDefinition&lt;?, ?, ?&gt; def : defs){
           process(def);
       }
  }
  
  private &lt;K, V extends FileEntry, T extends ParsedFile&lt;K, V&gt;&gt; process(FileDefinition&lt;K, V, T&gt; def){
       Factory&lt;T&gt; factory = def.getFactory();
       MetricsProducer&lt;K, V&gt; producer = def.getMetricsProducer();
       ParsedFile&lt;K, V&gt; parsedFile = factory.parseFile();
       Metrics metrics = producer.generateMetrics(parsedFile);
  }
  </code></pre>
  
  <p>Thanks for the suggestions.</p>