The standard class...is it mutable or not?
A mutable object can be changed after it's created, and an immutable object can't. In Java, everything (except for strings) is mutable by default: public class IntegerPair { int x; int y; IntegerPair(int x, int y) { this.
To properly define mutable and immutable classes, one must first define what it means for an object instance to be mutable. An object instance is mutable if there is any possible(*) means via which the state encapsulated thereby might be modified. An object instance is immutable if its state cannot possibly be changed.
In object-oriented and functional programming, an immutable object (unchangeable object) is an object whose state cannot be modified after it is created. This is in contrast to a mutable object (changeable object), which can be modified after it is created.
String is an example of an immutable type. A String object always represents the same string. StringBuilder is an example of a mutable type. It has methods to delete parts of the string, insert or replace characters, etc.
It depends strongly on the language. Some of them do not even allow mutable objects.
Many mainstream languages default to being highly mutable, depending on what members you expose on your class's public interface. In at least a couple mainstream languages (particularly dynamic languages) it is really hard to make immutable objects.
See a definition of (im)mutable for more information:
In object-oriented and functional programming, an immutable object is an object whose state cannot be modified after it is created. This is in contrast to a mutable object, which can be modified after it is created.
A mutable class is one that can change its internal state after it is created.
Generally speaking, a class is mutable unless special effort is made to make it immutable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With