Assignments to and from simple-type fields are straightforward
even if you mix reference and value types. For example, if you declare
a constant of a reference type such as STRING, the assigned value
is protected:
const myString STRING = "Unchanging";
myString = "Error!"; // not valid
A constant of a reference type other than a simple type
can be
updated. For example, you can update the elements in a constant of
type INT[] because INT[] is a reference type, and only the reference
to the list is constant. However, the first of the following two rules
indicates the difference between a constant of type STRING and a constant
of type INT[]:
- When a simple-type reference field receives a value from a value
field or literal, a boxing conversion occurs. The source
value is assigned to a new memory area, and the address of that area
is assigned to the reference field. The attempt to update a constant
of type STRING is not valid because the constant cannot reference
a different memory area.
- When a simple-type value field receives a value from a reference
field, an unboxing conversion occurs. The value field
receives the business value to which the reference field refers.