3 ms·
The "encapsulation" example is an interesting one, because it sits right in the fundamental difference between a Rust reference and a Java one, and the lifecycl
by mathw 9y ago
The "encapsulation" example is an interesting one, because it sits right in the fundamental difference between a Rust reference and a Java one, and the lifecycle considerations of a garbage-collected language vs one where lifecycles are statically determined by the compiler.
I guess one way to explain it, if one needed to, is to say that the Java object is effectively a collection of Rc<RefCell<T>>, and getters return copies of those Rc<>s. (Okay I know, garbage collection is not the same as refcounting, but in this kind of analysis it's effectively the same).
Makes me sit back and think how much work Java the language is doing for you here.