https://kotlinlang.org logo
#announcements
Title
# announcements
j

Joan Colmenero

10/19/2019, 3:42 PM
Having this
sealed class
?
Copy code
sealed class ResultWrapper<T> {
data class Success<T>(val data: T) : ResultWrapper<T>()
data class Unauthorized(val exception: UnauthorizedException) : ResultWrapper<Nothing>()
data class Forbidden(val exception: ForbiddenException) : ResultWrapper<Nothing>()
data class Network(val exception: NetworkException) : ResultWrapper<Nothing>()
data class NotFound(val exception: NotFoundException) : ResultWrapper<Nothing>()
data class BadRequest(val exception: BadRequestException) : ResultWrapper<Nothing>()
data class Error(val exception: Exception) : ResultWrapper<Nothing>()
}
Then I have a method that returns a
ResultWrapper<T>
but I'm only able to return the
ResultWrapper.Success(it)
how can I return the other ones?
d

Dominaezzz

10/19/2019, 3:47 PM
What happens when you try to return the other ones?
j

Joan Colmenero

10/19/2019, 4:03 PM
I solved it adding a <T> in front and changing the <Nothing> by <T>.
k

Kroppeb

10/19/2019, 4:04 PM
I think
sealed class ResultWrapper<out T>
should have worked fine too.
j

Joan Colmenero

10/19/2019, 4:20 PM
True that.
5 Views