title: Generic interface and implementation - type cannot be converted
body: <p>I have a generic interface defined as:</p>
  
  <pre><code>public interface ItemService&lt;T extends Slicer, E extends ItemSlice&gt; {
      E getItemHistory(final String id, final T slicer);
  }
  </code></pre>
  
  <p>And an implementation:</p>
  
  <pre><code>public class DynamoDbItemService implements ItemService&lt;DynamoDbSlicer, DynamoDbItemSlice&gt; {
      public DynamoDbItemSlice getItemHistory(final String id, final DynamoDbSlicer slicer) {
      }
  }
  </code></pre>
  
  <p>Here are the definitions of the four classes referenced above:</p>
  
  <pre><code>public interface Slicer {
      Map&lt;String, ? extends Serializable&gt; pointer();
  }
  
  public class DynamoDbSlicer implements Slicer {
      public Map&lt;String, AttributeValue&gt; pointer() {
      }
  }
  
  public interface ItemSlice extends Slice&lt;Item&gt; {
  }
  
  public interface Slice&lt;T&gt; {
      List&lt;T&gt; data();
      Slicer next();
  }
  
  public class DynamoDbItemSlice implements ItemSlice {
      publi ImmutableList&lt;Item&gt; data() {}
      public DynamoDbSlicer next() {}
  }
  </code></pre>
  
  <p>I would like to reference the <code>ItemService</code> interface but for it to be bound to the <code>DynamoDbItemService</code> implementation so I can swap it out if necessary which I can do like so:</p>
  
  <pre><code>ItemService&lt;? extends Slicer, ? extends ItemSlice&gt; itemService = new DynamoDbItemService itemService();
  </code></pre>
  
  <p>but if I try to use <code>itemService</code> like this:</p>
  
  <pre><code>ItemSlice slice = itemService.getItemHistory(itemId, DynamoDbSlicer.first(1));
  slice = itemService.getItemHistory(itemId, slice.next());
  </code></pre>
  
  <p>I get these two compilation errors:</p>
  
  <pre><code>Error:(231, 82) java: incompatible types: item.pagination.DynamoDbSlicer cannot be converted to capture#1 of ? extends pagination.Slicer
  
  Error:(238, 62) java: incompatible types: pagination.Slicer cannot be converted to capture#2 of ? extends pagination.Slicer
  </code></pre>
  
  <p>I understand from <a href="https://stackoverflow.com/questions/22024056/java-extends-i-cannot-be-converted-to-extends-i">this question</a> that <code>?</code> wildcards cannot be identical so my question is - can I do what I want - work with the interface? If so, how? Or am I approaching this incorrectly?</p>
  
  <p>I have asked two previous questions related to this which have helped along the way (<a href="https://stackoverflow.com/questions/56365964/attempting-to-use-incompatible-return-type-with-class-implementing-serializabl">first</a> and <a href="https://stackoverflow.com/questions/56369141/incompatible-type-generic-interface-and-implementation">second</a>)</p>