Skip navigation.
KDE Developer's Journals

What passes for grad work today... LOL

manyoso's picture

<SadEagle> public int hashCode() {
<SadEagle> /* This is probably a fairly bad hash function */
<SadEagle> return 0;
<SadEagle> }

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
jimmy_h's picture

Although it should be noted...

In Java, it is a violation of contract for objects for which:

o1.equals(o2)
and:
o1.hashCode() != o2.hashCode()

But it is done all the time - how often do you see equals overriden without overriding the default hashcode, under which all objects are unique?

If you are just creating some objects that you know will be compared for equality, but you don't think they'll ever be hashed, returning a constant is a hackish but quick and not too inelegent way of keeping within the rules.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.