dave08
11/01/2022, 1:06 PMinner object
declaration? Something similar to:
class Foo {
val num = 1
inner class Bar {
val one = "something $num"
}
val bar = Bar()
init {
// use it:
println(bar.one)
}
}
Sam
11/01/2022, 1:08 PMSam
11/01/2022, 1:08 PMdave08
11/01/2022, 1:13 PMobject
.Sam
11/01/2022, 1:14 PMSam
11/01/2022, 1:14 PMdave08
11/01/2022, 1:16 PMdave08
11/01/2022, 1:19 PMThe point of the current design is that a named object is always a singleton. This is not possible with inner objects, that why they are prohibited.
And using anonymous objects doesn't seem like a big problem, TBH
dave08
11/01/2022, 1:19 PMdave08
11/01/2022, 1:21 PMelizarov
11/09/2022, 3:43 AMinner object Foo { ... }
is simply a confusing concept. Moreover, if you need it, you can always write:
val Foo = object { ... }
dave08
11/09/2022, 10:28 AMdave08
11/09/2022, 10:31 AMobject
is globally scoped, how could an inner object
be understood as not being scoped to the current instance of the containing class? That's exactly what inner
is doing... giving access to the current instance's properties.elizarov
11/09/2022, 11:42 AMelizarov
11/09/2022, 11:42 AMelizarov
11/09/2022, 12:05 PMdave08
11/09/2022, 12:11 PMclass SomeViewModel : ViewModel() {
fun someAction1() {}
fun someAction2() {}
inner object Buttons {
val button1 = ActionButton(R.string.action1, ::someAction1)
val button2 = ActionButton(R.string.action2, ::someAction2)
}
}
which is a simplified form of my use case...elizarov
11/15/2022, 3:44 PMdave08
11/16/2022, 1:17 PM