What type should I be putting in `???` such that `...
# announcements
e
What type should I be putting in
???
such that
toResult
won’t error? I’ve tried
Nothing
and it is not working
Copy code
sealed class ApiResult<T>

data class Success<T>(
    val msg: String,
    val data: T
) : ApiResult<T>()

data class Failure(
    val error: String,
    val errMsg: String
) : ApiResult<???>()

fun toResult(): ApiResult<User> {
        return if (error == "0") Success(
            msg = msg, data = movies
        ) else Failure(error = error, errMsg = errMsg)
    }
Using
Nothing
got me error
Required: ApiResult<User>, Found: Failure
k
Unit
maybe?
m
Make
T
covariant by marking it with
out
. Then
Nothing
should work.
1
So
Copy code
sealed class ApiResult<out T>

data class Success<T>(
    val msg: String,
    val data: T
) : ApiResult<T>()

data class Failure(
    val error: String,
    val errMsg: String
) : ApiResult<Nothing>()
That will make
ApiResult<Nothing>
a subtype of
ApiResult<T>
for all
T
.
e
out
trick works!! Thanks
m
No problem
d
Shouldn't you just remove the type parameter on ApiResult, and keep it on Success?