Why the former works with the type inference when ...
# android
l
Why the former works with the type inference when the latter doesn’t?
s
T
is expected to be of type
Any
and your passing
Any?
. Generally
Any?
is the base class for everything in kotlin.
l
but why the same method outside the extension works without complaining about type?
d
The problem is that you get a union type. If it succeeds, you get T, else, you get NetworkErrorHandler.
Which is represented as Any.
Or you get a union with Unit.
Instead of
recover
, consider using
onFailure
Is this a library class? You're normally not able to return
Result
.
s
You can fix this by having NetworkErrorHandler return "Nothing" I believe
image.png
notice how s is <String> and s2 is <any> the Nothing signals to the compiler it will throw
l
Oh got it now, thanks guys!