
reference.language.category_mutability.html Maven / Gradle / Ivy
Categories
Mutability
Attribute values are normally set when creating objects.
This covers most use cases, but there are situations where you want to set or change attribute values after object creation.
Setting attribute value after object creation is done using assignment statements of the form instance.name = expression
,
where instance
is a value, name
is the name of a an attribute supported by this value, and expression
is an expression returning a value compatible with the type of name
.
However, it is worth reminding that unless specified, Prompto values are immutable.
As a consequence, the below code is illegal and cannot be executed:
This is because the Person object assigned to variable p is not marked as mutable
.
In order to set an attribute value after object creation, the category instance must me marked as mutable when created. The below code will run: