Specifications
Sun Services
Java™ Programming Language
Module 6, slide 37 of 43
Copyright 2005 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision F
An equals Example
11
12 public boolean equals(Object o) {
13 boolean result = false;
14 if ( (o != null) && (o instanceof MyDate) ) {
15 MyDate d = (MyDate) o;
16 if ( (day == d.day) && (month == d.month)
17 && (year == d.year) ) {
18 result = true;
19 }
20 }
21 return result;
22 }
23
24 public int hashCode() {
25 return (day ^ month ^ year);
26 }
27 }










