title: Casting consumer generic type to another type
body: <p>Please first look at my code. I get an error in the BolBFS constructor when I want to create an object:</p>
  <pre class="lang-none prettyprint-override"><code>Error:
  Required type is : Consumer&lt;Node&lt;String, ChildFlightConsignmentInfo&gt;&gt;
  Provided type is : Consumer&lt;BolNode&gt;
  </code></pre>
  <p>I know I can't cast <code>consumer&lt;T&gt;</code> to <code>consumer\&lt;? extends T&gt;</code>, but I don't know why, and how should I handle this problem?<br>
  If I change Node&lt;Identifire, Data&gt; to N, I have another problem in the <strong>adj()</strong> method in class BFS.</p>
  <pre class="lang-none prettyprint-override"><code>Error:
  Required Set&lt;N&gt;
  Provided Provided Set&lt;Node&lt;Identifier, Data&gt;&gt;
  </code></pre>
  <p>This is my code:</p>
  <p>BolBFS.java constructor:</p>
  <pre class="lang-java prettyprint-override"><code>public BolBFS(TraverseDirection dir, BolNode root, Consumer&lt;BolNode&gt; consumeEachBol, Predicate&lt;BolNode&gt; setFlagCondition, Predicate&lt;BolNode&gt; stopCondition) {
      BFS&lt;String, ChildFlightConsignmentInfo, BolNode&gt; bfs =  new BFS&lt;&gt;(dir, root, consumeEachBol, setFlagCondition, stopCondition);
  }
  </code></pre>
  <p>BolNode.java:</p>
  <pre class="lang-java prettyprint-override"><code>public class BolNode extends Node&lt;String, ChildFlightConsignmentInfo&gt;
  </code></pre>
  <p>BFS.java:</p>
  <pre class="lang-java prettyprint-override"><code>public class BFS&lt;Identifier, Data, N extends Node&lt;Identifier, Data&gt;&gt; implements Serializable {
  
      protected TraverseDirection dir;
      protected volatile Queue&lt;Node&lt;Identifier, Data&gt;&gt; nextToVisit;
      protected volatile boolean flag;
      protected volatile Set&lt;Object&gt; visited;
      protected Consumer&lt;Node&lt;Identifier, Data&gt;&gt; consumer;
      protected Predicate&lt;Node&lt;Identifier, Data&gt;&gt; checker;
      protected Predicate&lt;Node&lt;Identifier, Data&gt;&gt; stopCondition;
      protected volatile Map&lt;Object, Node&lt;Identifier, Data&gt;&gt; predecessor;
      protected volatile Map&lt;Integer, Set&lt;Node&lt;Identifier, Data&gt;&gt;&gt; levels;
      protected volatile Map&lt;Object, Set&lt;Object&gt;&gt; adjList;
      protected volatile Map&lt;Object, Node&lt;Identifier, Data&gt;&gt; idMap;
  
      public BFS(TraverseDirection dir, Node&lt;Identifier, Data&gt; root, Consumer&lt;Node&lt;Identifier, Data&gt;&gt; consumer, Predicate&lt;Node&lt;Identifier, Data&gt;&gt; checker, Predicate&lt;Node&lt;Identifier, Data&gt;&gt; stopCondition) {        this.dir = dir;
          this.flag = false;
          this.checker = checker;
          this.consumer = consumer;
          this.stopCondition = stopCondition;
          this.predecessor = new ConcurrentHashMap&lt;&gt;();
          this.levels = new ConcurrentHashMap&lt;&gt;();
          this.adjList = new ConcurrentHashMap&lt;&gt;();
          this.idMap = new ConcurrentHashMap&lt;&gt;();
          idMap.put(root.getId(), root);
          levels.put(0, Stream.of(root).collect(Collectors.toSet()));
          logic(root, consumer, checker, stopCondition);
      }
      protected Map&lt;TraverseDirection, Set&lt;N&gt;&gt; adj(N node) {
          Map&lt;TraverseDirection, Set&lt;N&gt;&gt; result = new ConcurrentHashMap&lt;&gt;();
          result.put(TraverseDirection.ANY, node.getChild());
          return result;
      }
  
  }
  </code></pre>
  <p>Node.class:</p>
  <pre class="lang-java prettyprint-override"><code>public abstract class Node&lt;Identifier, Data&gt; implements Serializable {
      public abstract Set&lt;Node&lt;Identifier, Data&gt;&gt; getChild();
      }
  </code></pre>