when an anonymous object captures a `var` referenc...
# announcements
k
when an anonymous object captures a
var
reference from the adjacent scope in one of its methods, does it not see changes to the original reference (i.e., it captures its own reference to the value when the object is created)?
Copy code
var foo: String? = null
val bar = object {
    fun doSomething() { println(foo) }
}
foo = "hello world"
bar.doSomething()
d
Assuming this is inside a method, then
var foo
will compile to a
kotlin.jvm.internal.Ref.ObjectRef<String>
to hold the number. This way the object can capture the value of that container class to also see any external changes.
k
oh I think I see what I am doing wrong... chaining the scoping operators is delaying the
var
being set
i didn't include that in my example
yep, that was it