posted 18 years ago
Choose any three that apply
Given the following class, which are correct implementations of the hashCode() method?
class ValuePair {
public int a, b;
public boolean equals(Object other) {
try {
ValuePair o = (ValuePair) other;
return (a == o.a && b == o.b)
|| (a == o.b && b == o.a);
} catch (ClassCastException cce) {
return false;
}
}
public int hashCode() {
// Provide implementation here.
}
}
Answers
1. return 0;
2. return a;
3. return a+b;
4. return a-b;
5. return a^b;
6. return (a<<16)|b;
I'm sure that hashCode() method can
5. return a^b (an exclusive OR operation) and
1. return 0;
What is the other one which it can return.. with justification...
Thanks in advance... !!
rAm