harry.singh
10/14/2019, 11:41 AMEvan R.
10/14/2019, 2:52 PMharry.singh
10/15/2019, 7:41 AMclass C {
// Private function, so the return type is the anonymous object type
private fun foo() = object {
val x: String = "x"
}
// Public function, so the return type is Any
fun publicFoo() = object {
val x: String = "x"
}
fun bar() {
val x1 = foo().x // Works
val x2 = publicFoo().x // ERROR: Unresolved reference 'x'
}
}
x2
as its type is Any
but what I don't understand is how are we able to access anonymous object internals via x1
? I'm more interested in what trick does Kotlin employ to achieve this.