title: How to write hashCode method for a particular class?
body: <p>I'm trying to generate a hashCode() method for my simple class but i'm not getting anywhere with it. I would appreciate any help. I've implemented the equals() method, which looks as follows, and would also like to know if I need to implement compareTo() method. I've imported java.lang.Character to use character.hashCode() but it doesn't seem to work.</p>
  
  <pre><code>private class Coord{
      private char row;
      private char col;
      public Coord(char x, char y){
          row = x;
          col = y;
      }
      public Coord(){};
  
      public char getX(){
          return row;
      }
  
      public char getY(){
          return col;
      }
  
      public boolean equals(Object copy){
          if(copy == null){
              throw new NullPointerException("Object entered is empty");
          }
          else if(copy.getClass()!=this.getClass()){
              throw new IllegalArgumentException("Object entered is not Coord");
          }
          else{
              Coord copy2 = (Coord)copy;
              if(copy2.row==this.row &amp;&amp; copy2.col==this.col)
                  return true;
              else
                  return false;
          }
      }
  
  }
  </code></pre>
  
  <p>Thanks in advance...</p>
  
  <p>The comparTo() method that is giving me java.lang.Comparable casting error..</p>
  
  <pre><code>public int compareTo(Object copy){
          if(copy==null){
              throw new NullPointerException("Object entered is empty");
          }
          else if(copy.getClass()!=this.getClass()){
              throw new IllegalArgumentException("Object entered is not Coord");
          }
          else{
              Coord copy2 = (Coord)copy;
              if(copy2.row==this.row &amp;&amp; copy2.col==this.col){
                  return 0;
              }
              else if(copy2.col &lt; this.col){
                  return -1;
              }
              else{
                  return 1;
              }
          }
      }
  </code></pre>
  
  <p>thanks...</p>