Closed Ach113 closed 3 years ago
The method changes the data in-place, so no, it does not get discarded
but when function returns, doesn't the change caused by the
.set()
method get discarded?
No. In Java, all objects are passed by reference. The object goes out of scope in this function, but the original object retains its modifications.
Taken from the chapter 12 (Classes), this is how visitor of Set expression is defined:
I don't understand how this affects the state of the callee object. Here we see that
object
field ofSet
gets evaluated to get the callee, then.set()
method gets called, which changes the state ofObject object
, but when function returns, doesn't the change caused by the.set()
method get discarded?