Hi, I have this class representing LoadingState of...
# getting-started
d
Hi, I have this class representing LoadingState of some data:
Copy code
sealed 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
Copy code
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
Copy code
when (it) {
    is LoadingState.Loaded<*> -> handleData(it.data as MyData)
}
but that is not very nice