title: Why does comparison of objects return false in my snake game
body: <pre><code>public class Snake {
  
      private int snakeLength;
      private Position[] snakeBody;
  
      public Snake(int row, int col) {
          snakeLength = 1;
          snakeBody = new Position[5];
          Position initial = new Position(row, col);
          snakeBody[0] = initial;
      }
  
      public boolean snakePosition(Position pos) {
          boolean test = false;
          for(int i = 0; i &lt;= snakeBody.length-1;i++) {
              if (snakeBody[0] != null) {
                  boolean isEqual = pos.equals(snakeBody[0]);
                  if (isEqual == true) {
                      test = true;
                  }
              }
          }
          return test;
      } 
  </code></pre>
  
  <p>main method:</p>
  
  <pre><code>public class TestAsmt1 {
  
  public static void main(String[] args) {
  
  
  testPassed = true;
  theSnake = new Snake(1,1);
  if (!theSnake.snakePosition(new Position(1,1))) testPassed = false;
  </code></pre>
  
  <p>Position:</p>
  
  <pre><code>public class Position {
  
      private int positionRow;
      private int positionColumn;
  
      public Position(int row, int column) {
          positionColumn = column;
          positionRow = row;
      }
  
      public boolean equals (Position otherPosition) {
          if(otherPosition.getRow() == this.getRow() &amp;&amp; otherPosition.getCol() == this.getCol() ) {
              return true;
          } else {
          return false;
          }
      }
  
  
  }
  </code></pre>
  
  <p>I don't get why when I compare the objects it returns false. testpassed is supposed to me true. What am I doing wrong? I have been trying to figure this out for at least 2 hours now. Look at the if(pos.equals(snakeBody[i])) line in particular. I saw someone else had this issue too yesterday (this assignment is due tonight at midnight) but they couldn't get it solved. Any idea what the issue is?</p>