Section 3.4 of Java Concurrency in Practice says that an object is immutable if:
- Its state cannot be modified after construction;
- All its fields are final; and
- It is properly constructed (the
this
reference does not escape during construction)
Why does allowing the this
reference to escape during construction prevent an object from being immutable?
Note that I understand there are many problems associated with allowing the this
reference to escape during construction. My particular question here is why it prevents an object from being considered immutable.