Kris Wong
02/05/2020, 3:10 PMvar
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)?Kris Wong
02/05/2020, 3:12 PMvar foo: String? = null
val bar = object {
fun doSomething() { println(foo) }
}
foo = "hello world"
bar.doSomething()
diesieben07
02/05/2020, 3:14 PMvar 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.Kris Wong
02/05/2020, 3:16 PMvar
being setKris Wong
02/05/2020, 3:16 PMKris Wong
02/05/2020, 3:18 PM