title: Error when using Collections.sort() with ArrayList and Class. (JAVA)
body: <p>I'm actually trying to order an ArrayList using external sorting (I know it's easier than this, but my teacher wants it like this).</p>
  
  <p>I have the next code:</p>
  
  <pre><code>//MainClass
  
      public static void main(String[] args) {
          Cotxe coche1 = new Car("Opel","Corsa",200);
          Cotxe coche2 = new Car ("Ferrari","Italia",200);
          Cotxe coche3 = new Car ("Porsche","Cayenne",200);
  
          ArrayList&lt;Car&gt; list = new ArrayList&lt;Car&gt;();
  
          list.add(car1);
          list.add(car2);
  
          Collections.sort(list, new OrderCarByModel());
      }
  
  //COMPARATOR CLASS
  
  public interface Comparator &lt;Car&gt;{
      int compare(Car c1, Car c2);
      boolean equals(Object obj);
  }
  
  //ORDERCARBYMODEL CLASS
  
  public class OrderCarByModel implements Comparator&lt;Car&gt; {
      @Override
      public int compare(Car c1, Car c2) {
          return c1.getModel().compareTo(c2.getModel());
      }
  
  //CAR CLASS ONLY HAVE 3 ATTRIBUTES. BRAND, MODEL AND PRICE, IT'S A PRETTY SIMPLE CLASS.
  </code></pre>
  
  <p>The error comes in the "Collections.sort(list, new OrderCarByModel());" in the MainClass.</p>
  
  <p><a href="https://i.stack.imgur.com/7bN0o.png" rel="nofollow noreferrer">Sorry for the translation, I just translated the code in the post but not in the error picture, "Cotxe" means "Car" and "OrdenarCocheModelo" means "OrderCarByModel".</a></p>