I think that was a confused question. Strings do some special magic to make your s1==s2. Writing the literal "abc" generates a String object which is "interned" into a string pool. When you reference "abc" again, the compiler sees there is already a "123" in the pool and uses it again.
That would be useless if String was not immutable. You wouldn't want to point to "123" in the pool and later find it says "abc". But the String magic is not part of being immutable. It's an optimization in the compiler.
You can make your own immutables, but you can't make your own magic pool. Immutable just means the state can't change. This will get you close enough for jazz: make all variables private, make no methods that modify variables, and make sure that any non-primitive variables reference objects that are also immutable.
You can defeat the immutability of such classes in
Java with the reflection API. Using a workaround to deliberately subvert a design is cheating and is likely to get you just the punishment you deserve.
Does that help?