title: distinct() method not returning distinct elements for stream of HashSet elements
body: <p>Let say I have Employee class with properly overridden equals and hashcode method.</p>
  
  <pre><code>public class Employee {
  
  private int eno;
  private String firstName;
  private String lastName;
  
  @Override
  public int hashCode() {
      System.out.println("hashcode called");
      final int prime = 31;
      int result = 1;
      result = prime * result + eno;
      result = prime * result + ((firstName == null) ? 0 : firstName.hashCode());
      result = prime * result + ((lastName == null) ? 0 : lastName.hashCode());
      return result;
  }
  
  @Override
  public boolean equals(Object obj) {
      System.out.println("equals called");
      if (this == obj)
          return true;
      if (obj == null)
          return false;
      if (getClass() != obj.getClass())
          return false;
      Employee other = (Employee) obj;
      if (eno != other.eno)
          return false;
      if (firstName == null) {
          if (other.firstName != null)
              return false;
      } else if (!firstName.equals(other.firstName))
          return false;
      if (lastName == null) {
          if (other.lastName != null)
              return false;
      } else if (!lastName.equals(other.lastName))
          return false;
      return true;
  }
  }
  </code></pre>
  
  <p>Testing class as below</p>
  
  <pre><code>class Test {
  
      public static void main(String[] args) {
  
          Employee e1 = new Employee(1, "Karan", "Mehara");
          Employee e2 = new Employee(2, "Rajesh", "Shukla");
  
          Set&lt;Employee&gt; emps= new HashSet&lt;&gt;();
          emps.add(e1);
          emps.add(e2);
          System.out.println(emps);
  
          // No such requirement just for testing purpose modifying 
          e2.setEno(1);
          e2.setFirstName("Karan");
          e2.setLastName("Mehara");
  
          System.out.println(emps);
  
          emps.stream().distinct().forEach(System.out::println);
      }
  
  }
  </code></pre>
  
  <p>The output of the above program is:</p>
  
  <p>[Employee [eno=1, firstName=Karan, lastName=Mehara], Employee [eno=2, firstName=Rajesh, lastName=Shukla]]</p>
  
  <p>[Employee [eno=1, firstName=Karan, lastName=Mehara], Employee [eno=1, firstName=Karan, lastName=Mehara]]</p>
  
  <p><strong>Employee [eno=1, firstName=Karan, lastName=Mehara]</strong></p>
  
  <p><strong>Employee [eno=1, firstName=Karan, lastName=Mehara]</strong></p>
  
  <p>Why distinct() method return duplicate elements?? </p>
  
  <p>According to equals() and hashcode() method of employee class both objects are the same.</p>
  
  <p>I have observed that when I call distinct() method equals() and hashcode() method <strong>won't get a call</strong> for a stream of <strong>Set implementation</strong> but it <strong>get a call</strong> for a stream of <strong>List implementation</strong>.</p>
  
  <p>As per JavaDoc says 
  distinct() Returns a stream consisting of the distinct elements <strong>(according to Object.equals(Object))</strong> of this stream.</p>
  
  <pre><code>/**
       * Returns a stream consisting of the distinct elements (according to
       * {@link Object#equals(Object)}) of this stream.
       *
       * &lt;p&gt;For ordered streams, the selection of distinct elements is stable
       * (for duplicated elements, the element appearing first in the encounter
       * order is preserved.)  For unordered streams, no stability guarantees
       * are made.
       *
       * &lt;p&gt;This is a &lt;a href="package-summary.html#StreamOps"&gt;stateful
       * intermediate operation&lt;/a&gt;.
       *
       * @apiNote
       * Preserving stability for {@code distinct()} in parallel pipelines is
       * relatively expensive (requires that the operation act as a full barrier,
       * with substantial buffering overhead), and stability is often not needed.
       * Using an unordered stream source (such as {@link #generate(Supplier)})
       * or removing the ordering constraint with {@link #unordered()} may result
       * in significantly more efficient execution for {@code distinct()} in parallel
       * pipelines, if the semantics of your situation permit.  If consistency
       * with encounter order is required, and you are experiencing poor performance
       * or memory utilization with {@code distinct()} in parallel pipelines,
       * switching to sequential execution with {@link #sequential()} may improve
       * performance.
       *
       * @return the new stream
       */
      Stream&lt;T&gt; distinct();
  </code></pre>