david.bilik
11/28/2017, 11:07 AMsealed class LoadingState {
object Loading : LoadingState()
data class Error(val err: Throwable) : LoadingState()
data class Loaded<T>(val data: T) : LoadingState()
object Empty : LoadingState()
}
and I want to have some check in UI to handle this states, so I have
when (it) {
is LoadingState.Loaded<MyData> -> handleData(it.data)
}
but I dont know how to do a type check with generics, because this code does not compile because of type erasure. I can have something like
when (it) {
is LoadingState.Loaded<*> -> handleData(it.data as MyData)
}
but that is not very nice