Why is it that they decided to make String
immutable in Java and .NET (and some other languages)? Why didn\'t they make it mutable?
One factor is that, if String
s were mutable, objects storing String
s would have to be careful to store copies, lest their internal data change without notice. Given that String
s are a fairly primitive type like numbers, it is nice when one can treat them as if they were passed by value, even if they are passed by reference (which also helps to save on memory).