Hi - why is `Foo` not available, but `Empty`? ```...
# getting-started
m
Hi - why is
Foo
not available, but
Empty
?
Copy code
interface IBaseViewState<out T> {
    object Foo : IBaseViewState<Nothing>
}

sealed interface IViewState<out T> : IBaseViewState<T> {
    object Loading : IViewState<Nothing>
    object Empty : IViewState<Nothing>
    data class Data<T>(val value: T) : IViewState<T>
    data class Error(val throwable: Throwable) : IViewState<Nothing>
}
r
It's not entirely clear what you're asking, but if you are saying you have a context where
Empty
is a valid value, but
Foo
isn't, I would guess it's because the context expects
IViewState
, which
Empty
is, but
Foo
isn't (it's only
IBaseViewState
)
m
That’s what I meant… and I am wondering about that, as I thought `Foo`to be valid too because of inheritance
k
available where?
m
Exactly like this, yes
m
In the given code snippet,
Foo
is declared as an object of the
IBaseViewState
interface, while
Empty
is declared as an object of the
IViewState
interface. Since
IBaseViewState
is a supertype of
IViewState
,
Foo
is not directly accessible from
IViewState
. However, you can access
Foo
by explicitly referencing the
IBaseViewState
interface, like this: val foo: IBaseViewState<Nothing> = IBaseViewState.Foo On the other hand,
Empty
is directly accessible from
IViewState
since it's declared within it. So, you can access it like this: val empty: IViewState<Nothing> = IViewState.Empty Both
Foo
and
Empty
are declared as objects, which means that they are singleton instances of their respective classes/interfaces. So, you can use them directly without creating a new instance. Might be it work
k
point is that class/object definitions are not inherited