https://kotlinlang.org logo
#android
Title
# android
l

leosan

02/28/2019, 4:33 PM
Why the former works with the type inference when the latter doesn’t?
s

shubh10

02/28/2019, 4:45 PM
T
is expected to be of type
Any
and your passing
Any?
. Generally
Any?
is the base class for everything in kotlin.
l

leosan

02/28/2019, 4:50 PM
but why the same method outside the extension works without complaining about type?
d

Dico

02/28/2019, 11:04 PM
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

sitepodmatt

03/01/2019, 1:55 AM
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

leosan

03/01/2019, 9:07 AM
Oh got it now, thanks guys!
2 Views