title: Generic methods in java. How to match generic parameters
body: <p>I have this entity-relation model:</p>
  
  <pre><code>// Entity interface
  public interface Entity&lt;Reference extends Entity&lt;Reference&gt;&gt; extends Iterable&lt;Attribute&lt;Reference, ?&gt;&gt; {
  
      // set a referrer and the RelationMetadata to this Entity
      &lt;Referrer extends Entity&lt;Referrer&gt;&gt; void setReferrer(RelationMetadata&lt;Referrer, Reference&gt; relationMetadata, Referrer referrer);
  
      some other methods...
  
  }
  
  // Relation Metadata is a relation descriptor
  public class RelationMetadata&lt;Referrer extends Entity&lt;Referrer&gt;, Reference extends Entity&lt;Reference&gt;&gt; {
  
      some methods...
  
  }
  </code></pre>
  
  <p>I want to create my Entity ('selectedEntity') reading its metadata, loading its referrers and connect these to 'selectedEntity'. So my usage is that:</p>
  
  <pre><code>// obtain the entity metadata
  EntityMetadata&lt;E&gt; entityMetadata = EntityManager.getEntityMetadata(selectedEntity.getClass());
  
  // cycle on each relation my entity is reference
  for (Iterator&lt;RelationMetadata&lt;? extends Entity&lt;?&gt;, E&gt;&gt; iterator = entityMetadata.getAsReferencesRelationsMetadataIterator(); iterator.hasNext();) {
  
      // for each relation
      RelationMetadata&lt;? extends Entity&lt;?&gt;, E&gt; relationMetadata = (RelationMetadata&lt;? extends Entity&lt;?&gt;, E&gt;) iterator.next();
  
      // instance dao     
      Dao&lt;?&gt; referrerDao = DaoManager.getDao(relationMetadata.getReferrer());
  
      some code..
  
      // select referrer entity
      Entity&lt;?&gt; referrer = referrerDao.selectByKey(...);
  
      // set referrer to my 'selectedEntity'
      selectedEntity.setReferrer(relationMetadata, referrer);
  
  }
  </code></pre>
  
  <p>The problem is that I obtain this compiling error calling method 'setReferrer':</p>
  
  <pre><code>'The method setReferrer(RelationMetadata&lt;Referrer,E&gt;, Referrer) in the type Entity&lt;E&gt; is not applicable for the arguments (RelationMetadata&lt;capture#16-of ? extends Entity&lt;?&gt;,E&gt;, Entity&lt;capture#18-of ?&gt;)'
  </code></pre>
  
  <p>I know that 'referrer' I loaded is correctly connected to 'relationMetadata' but how can I hint that to compiler?</p>
  
  <p>That's a very annoying problem, I don't know how to solve it.</p>
  
  <p>Thank you
  G.</p>