Originally posted by Remko Strating:
Maybe this link can help you.
Well, if he's interested in utterly missing the point, sure.
The main reason strings are final and immutable is security. If you could change a String over time, then no code could trust the contents of a String, and any method that needed to look at a String would have to make a copy of it before doing anything with it at all. Otherwise the sandbox security model goes right to pieces. For example, what if you could ask for permission to connect to a given server, then later, after you get permission but before the system makes the connection for you, change the String containing the server name to some other server?
If you needed to copy a String to trust it, then not copying a String would be a bug, and people being the way they are, there'd be bugs like this being reported against the
Java APIs all the time. Ugh. Not to mention the inefficiency of making all those copies.