The true definition of immutability?

后端 未结 10 1898
被撕碎了的回忆
被撕碎了的回忆 2021-02-09 03:15

I am wondering how immutability is defined? If the values aren\'t exposed as public, so can\'t be modified, then it\'s enough?

Can the values be modified inside the type

10条回答
  •  有刺的猬
    2021-02-09 03:58

    Here is the definition of immutability from Wikipedia (link)

    "In object-oriented and functional programming, an immutable object is an object whose state cannot be modified after it is created."

    Essentially, once the object is created, none of its properties can be changed. An example is the String class. Once a String object is created it cannot be changed. Any operation done to it actually creates a new String object.

提交回复
热议问题