in reply to programming languages and immutable data types
If a type is immutable, functions and container objects can share the instance to save memory. In essence, it's a high level copy-on-write scheme.
If a type is immutable, you don't risk breaking code by accidentally sharing between functions and contained objects. Since strings are objects in Java, assigning a string to a variable shares the instance rather than making a copy.
If a type is immutable, you can share it across threads without having to use locks to read from it. This is an important factor in Java since it promotes the use of threads.
|
|---|