L
laredotornado
Hi,
I'm using Java 6. The Javadocs suggest that Map uses containsKey, and
hence an Object's equals method to determine if the object is already
a key in the map. However, I'm noticing that when I define this
equals method on an object I'm inserting as a key in my Map (a
HashMap):
public boolean equals(Object obj) {
SearchResultHotels hotel = (SearchResultHotels) obj;
boolean ret = obj != null && ((SearchResultHotels) obj).getId() ==
getId();
log.debug("\t comparing " + hotel.getName() + " to " + getName() +
":" + ret);
return ret;
}
I never see my log statement printed out when I call "map.put". What
am I missing?
Thanks, - Dave
I'm using Java 6. The Javadocs suggest that Map uses containsKey, and
hence an Object's equals method to determine if the object is already
a key in the map. However, I'm noticing that when I define this
equals method on an object I'm inserting as a key in my Map (a
HashMap):
public boolean equals(Object obj) {
SearchResultHotels hotel = (SearchResultHotels) obj;
boolean ret = obj != null && ((SearchResultHotels) obj).getId() ==
getId();
log.debug("\t comparing " + hotel.getName() + " to " + getName() +
":" + ret);
return ret;
}
I never see my log statement printed out when I call "map.put". What
am I missing?
Thanks, - Dave