I observe some behavior that is different from what is documented here (rather I think the docs are missing one case):
Copy code
interface Foo {
companion object {
val x = "SomeValue"
}
}
When the companion object is inside an interface then I don't see
Foo.Companion
or
Foo.companion.shared
.
Instead, the companion object is created at the top level, so the usage is:
FooCompanion.shared
curioustechizen
01/09/2024, 1:02 PM
In fact this is not restricted to companion objects. It also applies to any inner classes of an interface. One notable example is `sealed interface`s.
curioustechizen
01/09/2024, 1:52 PM
Copy code
sealed class Action {
data object OnCtaClicked: Action()
data class OnItemSelected(val index: Int): Action()
}
//Swift
Action.OnCtaClicked()
Action.OnItemSelected(index: 2)
curioustechizen
01/09/2024, 1:52 PM
versus interface:
Copy code
sealed interface Action {
data object OnCtaClicked: Action
data class OnItemSelected(val index: Int): Action
}
//Swift:
ActionOnCtaClicked()
ActionOnItemSelected(index: 2)