29 Copying a class
Call copy() when a new top-level class identity is needed.
norm
class Counter {
Integer value
}
main() {
Counter original = Counter(value: 2)
Counter copied = original.copy()
copied.value = 5
printLine(original.value)
printLine(copied.value)
printLine(original == copied)
}Expected output:
text
2
5
falseThe copy starts with the original field value, then changes independently. Equality remains false because class equality uses identity. Class objects held in fields remain shared unless copied separately.
Try it: Give the class a nested class field and inspect shallow-copy behavior.
Precise rules: Reference.