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

后端 未结 17 2026
不思量自难忘°
不思量自难忘° 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:32

    It's largely for security reasons. It's much harder to secure a system if you can't trust that your Strings are tamperproof.

提交回复
热议问题