title: Java abstract class generic method parameter
body: <p>I'm running into a problem with java abstract classes and generic functions. The implementation is a node class in a graph for Dijkstra's algorithm.</p>
  
  <pre><code>public abstract class Node {
  
      float distance;
      Node parent;
  
      public void relax(Node parent, Edge edge, PriorityQueue&lt;? extends Node&gt; priorityQueue) {
          if (this.distance &gt; parent.distance + edge.weight){
              this.distance = parent.distance + edge.weight;
              this.parent = parent;
              priorityQueue.remove(this);
              priorityQueue.add(this);
          }
      }
  }
  </code></pre>
  
  <p>The problem is the line: </p>
  
  <blockquote>
    <p>priorityQueue.add(this);</p>
  </blockquote>
  
  <p>Because <strong>this</strong> references the Node class (which is abstract) it cannot be added to the priority queue and should in fact be of type <strong>?</strong> (the subclass of node) denoted in <strong>? extends Node</strong>. How to I reference this subclass type?</p>
  
  <p>Thanks in advance.</p>