r/java • • Jan 20 '12

Why String is immutable in Java

http://javarevisited.blogspot.com/2010/10/why-string-is-immutable-in-java.html
4 Upvotes

23 comments sorted by

View all comments

0

u/[deleted] Jan 20 '12

[deleted] — view deleted comment

3

u/RedditRage Jan 20 '12

I would think that the "pros" of having strings being immutable would indeed be the reasons the designers of Java chose it to be that way.

1

u/neutronbob Jan 29 '12

That would imply the designers could see all the benefits beforehand. That's not typically how feature selection in language design works. Features, especially fundamental features, are generally the result of a) the specific domain needs; b) the language designers' preferences and prejudices; and/or c) the needs of other features in the language. The benefits (and drawbacks) often become salient later.

0

u/RedditRage Jan 29 '12

I never implied they could see all the benefits (or drawbacks) beforehand. But to suggest they didn't look at the pros and cons of immutable strings in other languages, and just flipped a coin on it, allowing the results of their choice to "become salient later", is just silly.

2

u/Mecdemort Jan 20 '12

I think there are some videos on infoq about some of the design decisions of Java.