Well, thats true. But if he loses the reference for a key ! there is
no way to retrieve the value against it !! Its risky but
implementation Dependant. As for the question, since you are making
use of the Objects equal method for comparing objects which is bit to
bit comparison, instinctively it tells that there might be performance
impact. If you have overridden the equals and hashcode methods it
would have been simpler, then it may not dependant on the object size
but just ur logic in those methods.
Regards,
Ravi
On Nov 23, 5:09 pm, Andreas Leitgeb <a...@gamma.logic.tuwien.ac.at>
wrote:
> > On Nov 23, 4:00 pm, rony.j...@gmail.com wrote:
> >> > > i am using a large object as key in hashmap without
[quoted text clipped - 9 lines]
> per definition unique (unequal to every other instance), then overriding
> Object's hashCode() and equals() shouldn't be necessary.
Andreas Leitgeb - 23 Nov 2007 15:17 GMT
>> > there is no problem but you must overide your equals ans hashcode
>> > method
[quoted text clipped - 4 lines]
> no way to retrieve the value against it !! Its risky but
> implementation Dependant.
Why not? You can easily (and without any risk) iterate the
HashMap, then you see all the elements inside, so nothing is
really lost.
> As for the question, since you are making
> use of the Objects equal method for comparing objects which is bit to
> bit comparison,
I don't think so: Object's equal() does only "compare" the Reference
itself; nothing of the data inside the object's instance is examined!
PS: Quoting rearranged.
Please respond *below* the parts that you respond to.
A: because the answer should follow the question.
Q: why?
:-)
Lew - 23 Nov 2007 16:39 GMT
>>>> there is no problem but you must overide your equals ans hashcode
>>>> method
[quoted text clipped - 13 lines]
> I don't think so: Object's equal() does only "compare" the Reference
> itself; nothing of the data inside the object's instance is examined!
It is actually quite common to use reference comparison in Map keys, i.e., not
to override equals(),
You only override equals() when a class's notion of equality requires value
comparison. Then, of course, you must also override hashCode() to be
consistent with equals().
Overriding equals(), like just about any rule of thumb, is not a law that you
must *always* follow. It's something you do if and only if the semantics of
your class need it.

Signature
Lew
Hendrik Maryns - 23 Nov 2007 16:54 GMT
Ravi schreef:
Please do not top-post.
> Well, thats true. But if he loses the reference for a key ! there is
> no way to retrieve the value against it !!
Um, what about map.keyset()?
> Its risky but
> implementation Dependant. As for the question, since you are making
> use of the Objects equal method for comparing objects which is bit to
> bit comparison, instinctively it tells that there might be performance
> impact.
No, it compares pointers.
H.
> On Nov 23, 5:09 pm, Andreas Leitgeb <a...@gamma.logic.tuwien.ac.at>
> wrote:
[quoted text clipped - 10 lines]
>> per definition unique (unequal to every other instance), then overriding
>> Object's hashCode() and equals() shouldn't be necessary.

Signature
Hendrik Maryns
http://tcl.sfs.uni-tuebingen.de/~hendrik/
==================
http://aouw.org
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html