https://kotlinlang.org logo
#getting-started
Title
# getting-started
s

Simas Butavičius

09/19/2021, 10:36 AM
EDIT: Answered in thread. Could someone please explain, why i can’t access anonymous object’s property, unless I declare val as private? Thank you for your time.
Copy code
class Demo {
    class Normal {
        val greeting = "I'm Normal class instance"
    }
    val normal = Normal()

    private val privateAnonymous = object {
        val greeting = "I'm anonymous class instance"
    }
    
    val anonymous = object {
        val greeting = "I'm also anonymous class instance"
    }
    
    val normalGreeting = normal.greeting // I'm Normal class instance
    val privateAnonymousGreeting = privateAnonymous.greeting // I'm anonymous class instance
    val anonymousGreeting = anonymous.greeting // Unresolved reference: greeting
}
s

Simas Butavičius

09/19/2021, 11:16 AM
@ephemient thank you very much. Missed this.