You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
but the problem is in calling code where i have to cast it to userList
and from the calling code i am calling it like
private fun fetchData() {
dataSource.getUsers()
.applySchedulers() //// **This an Extension Function which is mention above **
.bindUntilEvent(this, ActivityEvent.DESTROY)
.subscribe({ t ->
when (t) {
is Success<*> -> {
val payload = t.data as? List<User> ?: emptyList<User>() **I have to cast it to user List**
Log.d("users ", " ${payload} ")
//adapt.data = payload
}
}
}, { t -> t.printStackTrace() })
The text was updated successfully, but these errors were encountered:
It is because your Success class takes the raw Response.data as its member.
I will make the Success class into a Generic class Success, where T is your data's actual type, this way you can always get the exact type without manual casting.
sealed class State
object Loading : State()
data class Error(val msg: String): State()
data class Success<out T>(val islocal :Boolean = false,val msg: String,val data: T?): State()
i am using a state sealed class like this i am already using Success with generic data type for data member variable
i have some function which is like that
This is a Extension function
but the problem is in calling code where i have to cast it to userList
and from the calling code i am calling it like
The text was updated successfully, but these errors were encountered: