java - What is the need to override equals method in String class -
the reason behind asking question string in java interned
string s1 = "hello"; string s2 = "hello"; both s1 , s2 point same object in memory. 2 different objects not created.
s1.equals(s2) should return true , does. in java documentation says string class overrides equals method of object class. really?
because if string class not overrides equals method , output of equals method remain same.
if override why needed?
not "string in java interned". try reading file or console, strings aren't "interned", equals() (and hashcode()) needs overriden.
Comments
Post a Comment