title: Why do we have to override the equals() method in Java?
body: <p>I have some confusion about the reason that we override the <code>.equals</code> method.</p>
  
  <p>For example:</p>
  
  <pre><code>Test test1 = new Test(3);
  Test test2 = new Test(3);
  
  //The if comparison does the same thing that the overridden `.equals()` method does.
  if(test1.equals(test2)){
      System.out.println("test1 and test2 are true in .equals()");
  }
  
  // Override .equals method.
  public boolean equals(Object object) {
      if(object instanceof Test &amp;&amp; ((Test)object).getValue() == this.t) {
          return true;
      } else {
          return false;
      }
  }
  </code></pre>
  
  <p>I do not understand why we have to override the <code>.equals()</code> method.</p>