Anirudh Gupta
01/18/2025, 6:38 PMfun main() {
val vr = SnippetVR(object: Interaction {
override fun print() {
println("hello")
}
})
val snippet = vr.create()
snippet.print()
println("bye")
}
interface Interaction {
fun print()
}
class SnippetVR(val interaction: Interaction? = null) {
fun create(): Snippet {
return Snippet.newInstance().apply { this?.interaction = interaction }!!
}
}
class Snippet() {
companion object {
fun newInstance(): Snippet? = Snippet()
}
var interaction: Interaction? = null
fun print() {
interaction?.print()
}
}
On k1.9, the code outputs 'hello' as well as 'bye'
But on k2, 'hello' is not printed, only 'bye' is printed.
In k2, the interaction is being self assigned and not being picked from class variable.ephemient
01/18/2025, 10:17 PMChrimaeon
01/19/2025, 9:51 AMephemient
01/19/2025, 10:02 AMAnirudh Gupta
01/24/2025, 10:38 AM