java - Hashcode based on subclass? -
java - Hashcode based on subclass? -
probably mutual problem i'm not sure has solution in java
say have class a, class b, , class c. b , c extend a.
we have
set<a>
a has simple hashcode based on properties of a. problem when i'm adding b , c set, b , c may have same properties each other respect a.
obviously b has properties c doesn't , c has properties b doesn't. problem not able add together b , c set because hashcode (using a's hashcode function) same. , reasons (not explaining here) not allowed remove set a.
my problem comes downwards to, have 2 objects a, 1 of them b. however, respect set , hashcode, same. there anyway can express these 2 as, if properties same, not same?
what nice if a's hashcode function based on underlying subclass is. possible? anyway around problem?
override hashcode , equals methods in b , c well.
this way when hashing comes compare them include properties delegating downwards compare properties within a.
java inheritance polymorphism hashcode
Comments
Post a Comment