Mario Adam
05/03/2023, 6:09 PMFoo not available, but Empty?
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>
}Ruckus
05/03/2023, 8:01 PMEmpty 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)Mario Adam
05/04/2023, 6:24 AMkqr
05/04/2023, 7:03 AMkqr
05/04/2023, 7:05 AMMario Adam
05/04/2023, 7:07 AMMuhammad Utbah
05/04/2023, 7:47 AMFoo 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 workkqr
05/04/2023, 1:12 PM