title: Making your own class 'Comparable'
body: <p>I followed a tutorial, but failed to make my <code>Country</code> class <code>Comparable</code> for my <code>BST</code>. </p>
  
  <p>Main:</p>
  
  <pre><code>BinarySearchTree A = new BinarySearchTree();
  Country a = new Country("Romania", "Bucharest", 1112);
  A.insert(a);
  </code></pre>
  
  <p>Country class:</p>
  
  <pre><code>public int compareTo(Object anotherCountry) throws ClassCastException {
      if (!(anotherCountry instanceof Country))
          throw new ClassCastException("A Country object expected.");
      String anotherCountryName = ((Country) anotherCountry).getName();  
      int i = this.name.compareTo(anotherCountryName);
      if(i &lt; 0){
          return -1;
      } else {
          return 0;
      }
  }
  </code></pre>
  
  <p>error:</p>
  
  <pre><code>@Override
  public int compareTo(Object anotherCountry) throws ClassCastException {
      if (!(anotherCountry instanceof Country))
        throw new ClassCastException("A Country object expected.");
      String anotherCountryName = ((Country) anotherCountry).getName();  
      return this.name.compareTo(anotherCountryName);
  
  Description Resource    Path    Location    Type
  </code></pre>
  
  <p>Name clash: The method compareTo(Object) of type Country has the same erasure as compareTo(T) of type Comparable but does not override it    Country.java    /Lab2_prob 4/src    line 17 Java Problem</p>
  
  <pre><code>Description Resource    Path    Location    Type
  The method compareTo(Object) of type Country must override or implement a supertype method  Country.java    /Lab2_prob 4/src    line 17 Java Problem
  </code></pre>
  
  <p>and class:</p>
  
  <pre><code>public class Country implements Comparable&lt;Country&gt;{
      private String name;
      private String capital;
      private int area;
  
  Description Resource    Path    Location    Type
  </code></pre>
  
  <p>The type Country must implement the inherited abstract method Comparable.compareTo(Country)    Country.java    /Lab2_prob 4/src    line 2  Java Problem</p>