title: Inconvertible types in Generics
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/2745265/is-listdog-a-subclass-of-listanimal-why-arent-javas-generics-implicit">Is `List&lt;Dog&gt;` a subclass of `List&lt;Animal&gt;`? Why aren’t Java’s generics implicitly polymorphic?</a>  </p>
  </blockquote>
  
  
  
  <p>I need help understanding whats going on.</p>
  
  <p>I have an interface</p>
  
  <pre><code>public interface Foo {
  
    Map&lt;String, ParameterValue&gt; getParameters();
  }
  
  public interface ParameterValue { }
  </code></pre>
  
  <p>And an implementation of Foo.</p>
  
  <pre><code>class FooImpl implements Foo {
     Map&lt;String, ParameterValueImpl&gt; parameters = new HashMap&lt;String, ParameterValueImpl&gt;();
     //ParameterValueImpl an implementation of ParameterValue
  
  @Override
      public Map&lt;String, ParameterValue&gt; getParameters() {
          return ((Map&lt;String,ParameterValue&gt;) parameters);
      }   
  
  }
  </code></pre>
  
  <p>I get the following error</p>
  
  <pre><code>[ERROR] Failed to execute goal
  failure [ERROR]
  src/main/java/domainJPA/model/FooImpl.java:[92,45]
  inconvertible types [ERROR] found   :
  java.util.Map&lt;java.lang.String,domainJPA.model.ParameterValueImpl&gt;
  [ERROR] required:
  java.util.Map&lt;java.lang.String,domain.model.ParameterValue&gt;
  </code></pre>
  
  <p>I have to use the ParameterValue in the interface of Foo, and in FooImpl I must just the implementation of ParameterValue (ParameterValueImpl) because its an @Entity and jpa requires it.</p>
  
  <p>How can I make this code compile?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>If I change the code to <code>? extends ParameterValue</code> as suggested in one of the answers, then I cannot use the Foo interface.</p>
  
  <p>The following code results in compilation error: <code>The method put(String, capture#8-of ? extends ParameterValue) in the type Map&lt;String,capture#8-of ? extends ParameterValue&gt; is not applicable for the arguments (String, ParameterValueImpl)</code></p>
  
  <p><code>foo.getParameters().put("test", new ParameterValueImpl);</code></p>