How come the IDE complete `CardStatus.Companion.Pr...
# getting-started
r
How come the IDE complete
CardStatus.Companion.Present
instead of
CardStatus.Present
here?
Copy code
sealed class CardStatus(val value: Int) {
    companion object {
        fun fromInt(int: Int): CardStatus {
            return when(int) {
                255 -> PowerSavingMode
                3 -> Powered
                2 -> Present
                1 -> Absent
                else -> Error(int)
            }
        }

        object PowerSavingMode: CardStatus(255)
        object Powered: CardStatus(3)
        object Present: CardStatus(2)
        object Absent: CardStatus(1)
        data class Error(val errorValue: Int): CardStatus(errorValue)
    }
}
h
Just move the objects from the companion object into the sealed class
r
Huh, weird. Must be a Java thing? Does that mean they're properly attached to static namespace, or still part of a class instance?
k
Nested classes in Kotlin are like static nested classes in Java, i.e. they are not associated with an instance of their parent class, unless they are preceded by the
inner
keyword. Similarly with nested objects (in fact, I'm not sure what an "inner object" would even mean, if it were allowed).
r
Aye, makes sense. Thanks!