title: Java HashSet add() method is not calling overridden equals() method
body: <p>I have this code:</p>
  
  <pre><code>@Override
  public boolean equals(Object obj) {
  
      System.out.println("equals called");
  
      if(this == obj) {
          System.out.println("THIS object is the same as OBJ");
          return true;
      }
  
      System.out.println("obj.getClass() is " + obj.getClass());
      System.out.println("this.getClass() is " + this.getClass());
      if ((obj == null) || (obj.getClass() != this.getClass())) {
          return false;
      }
  
      double objOrbitalPeriod = ((HeavenlyBody) obj).getOrbitalPeriod();
      return this.orbitalPeriod == objOrbitalPeriod;
  }
  
  @Override
  public int hashCode() {
      return 0;
  }
  </code></pre>
  
  <p>In Main code is:</p>
  
  <pre><code>private static Set&lt;Planet&gt; solarSystem = new HashSet&lt;&gt;();
  public static void main(String[] args) {
      Planet planet = new Planet("Earth", 365.0);`
      solarSystem.add(planet);
      solarSystem.add(planet);
  }
  </code></pre>
  
  <p>Can someone explain why its not printing anything?</p>
  
  <p>I would expect it should print:
  <code>"equals called"</code></p>
  
  <p>and (as it is a duplicate):<code>"THIS object is the same as OBJ"</code></p>
  
  <p>But it seems there is something going on that I cannot understand.</p>