src/share/classes/java/util/Collection.java

Print this page
rev 7932 : 7057785: Add note to hashCode() that hash code calculation is optional for self-referential Collection/Map
Reviewed-by: duke

@@ -490,10 +490,15 @@
      * method must also override the <tt>Object.hashCode</tt> method in order
      * to satisfy the general contract for the <tt>Object.hashCode</tt> method.
      * In particular, <tt>c1.equals(c2)</tt> implies that
      * <tt>c1.hashCode()==c2.hashCode()</tt>.
      *
+     * @apiNote Support for calculation of hash code by self referential
+     * Collections (they either directly or indirectly contain themselves) is
+     * optional. Few Collection implementations support calculation of hash
+     * code for self referential instances.
+     *
      * @return the hash code value for this collection
      *
      * @see Object#hashCode()
      * @see Object#equals(Object)
      */