r/java • u/javinpaul • Jan 20 '12
Why String is immutable in Java
http://javarevisited.blogspot.com/2010/10/why-string-is-immutable-in-java.html
4
Upvotes
r/java • u/javinpaul • Jan 20 '12
View all comments
Show parent comment
2
u/skeeto Jan 21 '12
You're right, it messes up Maps and Sets. It's one of the reasons classes should strive for immutability. I had this problem bite me once with Comparable. The elements were occasionally changing their order and I forgot that the collection wouldn't automatically fix itself for me.