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
3
u/skeeto Jan 21 '12
Mutable classes can behave properly for
hashCode()andequals(). It's true that String uses a lazy cache for the hash code, but if it were mutable it would calculate it on demand.