The constructor stores a reference, not a copy:Now
val d = new Dimension(3, 4)
val f = new Frame(d)
d.width = 10f.area is still , but the product of its stored dimension fields is . Even without retaining d, a client can break the same invariant through f.dimension.height = 9, because the accessor exposes the same mutable object. This is representation exposure through reference aliasing. A val prevents reassigning the reference; it does not freeze the referenced object. Articles by others on the same topic
There are currently no matching articles.