Re: Map question
On Mon, 31 May 2010, Robert Klemme wrote:
On 31.05.2010 18:57, Tom Anderson wrote:
On Mon, 31 May 2010, Lew wrote:
Tom Anderson wrote:
if ((obj == null) || !(obj instanceof SearchResultHotels)) return false;
The '(obj == null)' clause is superfluous.
Good point.
My brain, for some reason, has a hard time remembering that:
SearchResultHotels x = (SearchResultHotels)null;
is okay but:
null instanceof SearchResultHotels
is false.
You just need to remember that null does not have a type. At least
that's what helped me to get this straight. :-)
Yes, when i think about it, it's all perfectly clear. But i get it wrong
when i'm not thinking about it.
In further penance, i should point out that the instanceof test is risky
if the class can have subclasses, and where those subclasses might have
different ideas about equality. A more conservative form might be:
if ((obj == null) || !(obj,getClass().equals(SearchResultHotels.class)) return false;
Also, "nothing" cannot really be an instance of "something", can it?
Ah, but you would agree that nothing can be an instance of everything!
tom
--
Judge Dredd. Found dead. Face down in Snoopy's bed.