package classes;

/**
 *
 * equals()
 * - for defining equivalence relation (reflexive, transitive, symmetric)
 * - must be consistent until object is modified
 * - used when search inside collection (e.g. contains, remove ...)
 * - tells whether you have found exact match
 * - default implementation in Object class use operator '='
 *
 * hashcode()
 * - must return consistent integer value for object during application execution
 * - used when inserting object into hashtable, hashmap or hashset
 * - tells which bucket to look in
 * - default implementation in Object class provides memory address
 *
 * Note
 * - if override one of them, then necessary to override the other one too
 * - same set of fields should be used to compute both
 * - If a.equals(b), then a.hashcode() and b.hashcode() must be same
 * - same hashcode for two objects doesn't guarantee one equals to other
 */
public class EqualsAndHashCode {
}

@@ -20,16 +20,18 @@
 **%0A *%0A *
+ -
  equals(
@@ -34,18 +34,16 @@
 als()%0A *
- -
  for def
@@ -102,26 +102,24 @@
 ymmetric)%0A *
- -
  must be con
@@ -153,18 +153,16 @@
 ified%0A *
- -
  used wh
@@ -219,18 +219,16 @@
  ...)%0A *
- -
  tells w
@@ -263,18 +263,16 @@
 match%0A *
- -
  default
@@ -329,22 +329,24 @@
 *%0A *
+ -
  hash
-c
+C
 ode()%0A *
  - m
@@ -341,18 +341,16 @@
 ode()%0A *
- -
  must re
@@ -421,18 +421,16 @@
 ution%0A *
- -
  used wh
@@ -486,18 +486,16 @@
 shset%0A *
- -
  tells w
@@ -519,18 +519,16 @@
 ok in%0A *
- -
  default
@@ -592,16 +592,18 @@
 *%0A *
+ -
  Note%0A *
  - i
@@ -598,18 +598,16 @@
  Note%0A *
- -
  if over
@@ -668,25 +668,59 @@
  one too%0A * 
--
+if override, both must be public%0A *
  same set of
@@ -760,18 +760,16 @@
  both%0A *
- -
  If a.eq
@@ -784,25 +784,25 @@
  then a.hash
-c
+C
 ode() and b.
@@ -805,17 +805,17 @@
 d b.hash
-c
+C
 ode() mu
@@ -827,18 +827,16 @@
  same%0A *
- -
  same ha
@@ -933,10 +933,357 @@
 hCode %7B%0A
+%09String name;%0A%09int versionId;%0A%09%0A%09@Override%0A%09public boolean equals(Object obj) %7B%0A%09%09if (obj instanceof EqualsAndHashCode)%0A%09%09%09return this.name.equals(((EqualsAndHashCode)obj).name) &&  %0A%09%09%09%09   this.versionId == ((EqualsAndHashCode)obj).versionId;%0A%09%09return false;%0A%09%7D%0A%09%0A%09@Override%0A%09public int hashCode() %7B%0A%09%09return name.hashCode() + versionId * 19;%0A%09%7D%0A
 %7D%0A

If equals return false, hashCode is not necessarily be true, can be false