Hi,
I am having a weird problem with the Contains method of an HashSet. My code involves comparing the "String" value of a variable "currentVar" in a set of "Strings" named "guardVars". Surprisingly, two
string variables having the exact same value is returning different hashcode value, and I believe this is causing the problem. Please find my code and output-print statements below:
Output:
Current-Var: destinationFromPlaying
HC of Current-Var: 1945131690
Set: [destinationFromPlaying, varActivity]
S: destinationFromPlaying HC of S: -491443146
S: varActivity HC of S: -656537770
Please note that I did not override the equals method here and so, I am not required to override hashcode as well, I think. Any explanation would be highly appreciated,
Thank you!