David Kubecka
06/10/2024, 12:22 PMstatus
val inside the apply
lambda?
val status: Int = 2
class Test(var status: Int)
Test(1).apply { status = status }
This version leads to self-assignment inside the class.Gleb Minaev
06/10/2024, 12:28 PMval status: Int = 2
class Test(var status: Int)
Test(1).apply { this.status = status }
"On my PC" status
is resolved as the first value. So I need to specify the property instead of value.David Kubecka
06/10/2024, 1:10 PMDavid Kubecka
06/10/2024, 1:15 PMDavid Kubecka
06/10/2024, 1:15 PMclass XXX {
val status: Int = 2
class Test {
var status: Int = 1
}
fun test() {
val test = Test().apply { status = status }
println(test.status)
}
}
fun main() {
XXX().test()
}
Prints 1, I want it to print 2.Klitos Kyriacou
06/10/2024, 1:19 PMstatus = this@XXX.status
because the implied this
inside your lambda refers to the innermost class, Test.Klitos Kyriacou
06/10/2024, 1:21 PMval test = Test().also { it.status = status }
David Kubecka
06/10/2024, 1:23 PMval status
is top-level 🤦 ThanksKlitos Kyriacou
06/10/2024, 1:42 PMval status
was a top-level declaration, and we used also { status = ???.status }
, how can we un-shadow the name so that it refers to the top-level status
?Roukanken
06/10/2024, 1:49 PMI don't know why I have mistakenly written at first that myIt's probably the Scratch file you mentioned, iirc they cause some implicit wrapping into classes (probably an artefact from Java)is top-levelval status
dmitriy.novozhilov
06/10/2024, 7:19 PMDaniel Pitts
06/10/2024, 8:40 PM