Bernhard
07/29/2024, 7:35 PMSkaldebane
07/29/2024, 8:01 PMSkaldebane
07/29/2024, 8:02 PMRobert Jaros
07/29/2024, 8:02 PMBernhard
07/29/2024, 8:03 PMSkaldebane
07/29/2024, 8:04 PMAny
inside another objectSkaldebane
07/29/2024, 8:05 PMdmitriy.novozhilov
07/30/2024, 6:11 AMpublic val
), its type will be approximated to the first supertype of this anonymous object
But if it is used in private declaration, then the approximation won't be applied, so you can actually call members of this object
class Some {
val publicObj/*: Any*/ = object {
fun foo() {}
}
private val privateObj/*: anon object*/ = object {
fun bar() {}
}
fun test() {
publicObj.foo() // error
privateObj.bar() // ok
publicTopLevel.foo() // error
privateTopLevel.bar() // ok
}
}
val publicTopLevel/*: Any*/ = object {
fun foo() {}
}
private val privateTopLevel/*: anon object*/ = object {
fun bar() {}
}