title: Java generics - incompatible equality constraint
body: <p>I am attempting to filter down a map to a sub set of itself. To achieve this I have attempted to implement the following utils method:</p>
  
  <pre><code>/**
  * Reduces the size of the map. Starts from the first entry in the map.
  * @param map The map.
  * @param size The size to reduce the map by.
  * @return The reduced size map.
  */
  public static &lt;T&gt; Map&lt;T, T&gt; subList(@NonNull Map&lt;T, T&gt; map, int size) {
    val sub = new HashMap&lt;T, T&gt;();
    for (Map.Entry&lt;T, T&gt; entry : map.entrySet()) {
        if (sub.size() &gt; size) {
            break;
        }
  
        sub.put(entry.getKey(), entry.getValue());
    }
    return sub;
  }
  </code></pre>
  
  <p>I am then attempting to use it like this:</p>
  
  <pre><code>@Override
  public Set&lt;FileTransfer&gt; upload(@NonNull ConnectionConfiguration target, @NonNull Map&lt;FileTransfer, File&gt; fileExports) {
      val batchSize = getBatchSize();
      if (fileExports.size() &gt; batchSize) {
          fileExports = (Map&lt;FileTransfer, File&gt;) MapUtils.subList(fileExports, batchSize);
      }
  
      ...
  }
  </code></pre>
  
  <p>But I am getting the error:</p>
  
  <blockquote>
    <p>reason: Incompatible equality constraint: FileTransfer and File</p>
  </blockquote>
  
  <p>I had assumed that I could pass a <code>Map&lt;FileTransfer, File&gt;</code> to the method because both types extend <code>Object</code>. What am I doing wrong here?</p>