title: Implementing Java Comparator
body: <p>I am trying to write an algorithm which utilizes a min-priority queue, so I looked around on google and found the PriorityQueue. It seems that in order to use it, though, I am going to need to tell it how I want it to prioritize, and that the way to do this is with a comparator (I want to compare specific data fields of my "Node1" objects). More googling presented the idea of creating a new comparator which implements Comparator but overrides the compare method. What I am trying is this (and other variations of it as well):</p>
  
  <pre><code>import java.util.Comparator;
  
  public class distComparator implements Comparator {
  
      @Override
      public int compare(Node1 x, Node1 y){
          if(x.dist&lt;y.dist){
              return -1;
          }
          if(x.dist&gt;y.dist){
              return 1;
          }
          return 0;
      }
  }
  </code></pre>
  
  <p>The compiler protests on several grounds, one of which is that I haven't over-ridden the comparator class (which it says is abstract)</p>
  
  <blockquote>
    <p>error: distComparator is not abstract and does not override abstract method compare(Object,Object) in Comparator</p>
  </blockquote>
  
  <p>I have switched it to say "compare(object x, object y)", which takes care of that issue. At this point though the compiler complains that it can't find the "dist" variable in x or y--which makes sense, since they are part of my Node1 class, not the Object class. </p>
  
  <p>So how is this supposed to work? It should have type <code>Object</code>, apparently, but then how do I direct it to the correct variable?</p>