Friday, November 1, 2002 09:49 AM
Suppose you have 2 object instances of your class, say object A has (string1="X", string2=null) and object B has (string1=null, string2="X"). With your implementation, the hashcode will be the same value (the hashcode of "X"), for both A and B.
Or suppose object A has (string1="ab", string2="c") and object B has (string1="a", string2="bc"). Your hashcode for both of these will be equal (the hashcode of "abc") and will even be equal to the hashcode for object C (string1="abc", string2=null) and for object D (string1=null, string2="abc"), and so on....
Perhaps to handle all these cases, you could just put a special separator in the middle, of your "sbf"/"str", before taking its hashCode. Use something for the separator string, which you know will never occur in either string1 or string2.