I have a class that generates hash code based only on limited amount of properties. One of the requirements for hashCode uniqueness is that one of the properties must be exactly the same object instance. See this sample code:
class A {
private B b;
public A(B p) {
b = p;
}
public int hashCode() {
???
}
}
Now the only cases where the hashCode will be equal is when a1.b == a2.b. The problem is that I don't know how to add object instance ID to hashCode. Using B.hashCode would fail - the fact that two object's hashCodes are equal doesn't mean the object are the same instance.
Edit: I really have problems explaining this problem. I'll try some more:
My A class has a property B b. When generating hashCode of A, two A should have same hashCode, if their b property is the same object instance. Along with this, two A's with different instances in b should have different hashCode. This should work regardless off how B.hashCode is generated.