Sanendak
06/26/2021, 4:52 PMSanendak
06/26/2021, 4:52 PMobject ExampleObject {
val objectInObject = object {
val number = 1
}
}
and I cannot get number. In example this not working
val test = ExampleObject.objectInObject.numberAkshat Sharma
06/26/2021, 4:54 PMclass GlobalVals {
companion object {
var numOfTimes: Int = 0
fun incNumOfTimes(){
numOfTimes = numOfTimes.inc()
}
}
}
Then i used them like this in main()
GlobalVals.incNumOfTimes()Sanendak
06/26/2021, 5:02 PMCLOVIS
06/26/2021, 5:13 PMobject ExampleObject {
object ObjectInObject {
val number = 1
}
}
Why do you want to put objects inside objects?CLOVIS
06/26/2021, 5:14 PMSanendak
06/26/2021, 5:24 PMsatyarth
06/27/2021, 7:32 AMCLOVIS
06/27/2021, 7:34 AMdmitriy.novozhilov
06/27/2021, 7:45 AMobjectInObject which was initiliazed by anonymous object. Since Anonymous object doesn't have any denotable name (actually it's name is ExampleObject$objectInObject$1), then compiler approximates type of objectInObject to its supertype (Any in this case), which obviously doesn't have property numberCLOVIS
06/27/2021, 8:12 AM