OnJava8-Examples/containers/Groundhog2.java

16 lines
440 B
Java
Raw Normal View History

2015-04-20 15:36:01 -07:00
//: containers/Groundhog2.java
2015-05-29 14:18:51 -07:00
// <20>2015 MindView LLC: see Copyright.txt
2015-04-20 15:36:01 -07:00
// A class that's used as a key in a HashMap
// must override hashCode() and equals().
public class Groundhog2 extends Groundhog {
public Groundhog2(int n) { super(n); }
2015-05-05 11:20:13 -07:00
@Override
2015-04-20 15:36:01 -07:00
public int hashCode() { return number; }
2015-05-05 11:20:13 -07:00
@Override
2015-04-20 15:36:01 -07:00
public boolean equals(Object o) {
return o instanceof Groundhog2 &&
(number == ((Groundhog2)o).number);
}
} ///:~