Question about Object Identity and Object Equality and String class exception

c#, equality, identity, java

Solution

Java and C# both use a memory-saving technique called string interning. Because strings are immutable in these languages, they can pool frequently-used strings (included hard-coded string literals, like in your example) and use multiple references to that one string in memory to save space.

Problem

This is a Java and C# question. We all know that, Object Identity(==) tests whether two objects refer to the same location and Obejct Equality(Equals method) tests whether two different (non identical)objects have the same value .But In case of string object Object Identity and Object Equality are same. For e.g Below two boolean expressions in if statements return true ``` string a="123"; string b="123"; if(a==b) if(a.Equals(b)) ``` Why is it so?? What is the rational behind this design decision?

Original source