Why can't strings be mutable in Java and .NET?

后端 未结 17 2025
不思量自难忘°
不思量自难忘° 2020-11-22 14:04

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?

17条回答
  •  悲哀的现实
    2020-11-22 14:40

    Immutability is not so closely tied to security. For that, at least in .NET, you get the SecureString class.

    Later edit: In Java you will find GuardedString, a similar implementation.

提交回复
热议问题