equals() and hashCode()
equals() and hashCode()
p1 reference
Person object
• Person p1 = new Person();
Person p2 = new Person();
Person object
p2 reference
• That way, you can use one instance when you add it to a
Collection and essentially re-create an identical instance when
you want to do a search based on that object as the key.
typically, this is not what you want so you must override equals()
• public boolean equals(Object obj)
10
hashCode() equals()
12
13
14
15
16
MutableFieldsTest program
18