jossiwolf
01/26/2019, 12:11 PMsuspend fun
from Java, but I can't access any properties of Result
- when implementing Continuation
, I only get an Object
in resumeWith
. Can anybody help with that? 🙂jossiwolf
01/26/2019, 12:11 PMservice.myApiCall(10, new Continuation<List<String>>() {
@NotNull
@Override
public CoroutineContext getContext() {
...
}
@Override
public void resumeWith(@NotNull Object result) {
// result should acutally be of type Result<List<String>>
}
});
Marc Knaup
01/26/2019, 12:20 PMjossiwolf
01/26/2019, 12:33 PMMarc Knaup
01/26/2019, 12:45 PMDico
01/26/2019, 12:59 PMResult.getValue(instance)
for exampleDico
01/26/2019, 1:00 PMDico
01/26/2019, 1:00 PMDico
01/26/2019, 1:01 PMDico
01/26/2019, 1:02 PMResult
typejossiwolf
01/26/2019, 2:41 PMresult
except for equals
, hashCode
and toString
, even if I cast it 😕Dico
01/26/2019, 2:43 PMDico
01/26/2019, 2:46 PMDico
01/26/2019, 2:50 PMList
, which is your continuation's T
. However, if you rely on that, you're relying on implementation details of Result
.jossiwolf
01/26/2019, 2:56 PMresumeWith
is being called with an Object
instead of my T
. There seems to be a static method called constructor-impl
on the class Result
, but I can't call it from Java because of the dash, so this sadly doesn't help me.Dico
01/26/2019, 3:04 PMDico
01/26/2019, 3:04 PMMarc Knaup
01/26/2019, 3:06 PMAny?
So Result<Whatever>
is Object
in Java because it doesn't use the inline class's wrapper class.Dico
01/26/2019, 3:07 PM@SuppressWarnings("KotlinInternalInJava")
@Override
public void resumeWith(@NotNull Object o) {
if (o instanceof Result.Failure) {
Throwable exception = ((Result.Failure) o).exception;
} else {
List<String> result = (List<String>) o;
}
}
Dico
01/26/2019, 3:08 PMMarc Knaup
01/26/2019, 3:10 PM@NotNull
seems to be wrong thoughDico
01/26/2019, 3:10 PMDico
01/26/2019, 3:11 PMDico
01/26/2019, 3:12 PM@NotNull
Dico
01/26/2019, 3:12 PMResult
type, but not the erased type of Any?
Marc Knaup
01/26/2019, 3:13 PMContinuation
interface in Java?
Makes senseDico
01/26/2019, 3:13 PMjossiwolf
01/26/2019, 3:22 PMresumeWith
called with a Result
in any case? If I got it correctly, casting Object o
to the T
wouldn't work because it's still a Result.Dico
01/26/2019, 3:23 PMResult
in Kotlin code, but because Result
is an inline class, the erased type or the type that's visible from Java is the type of the only field that Result
has.Dico
01/26/2019, 3:23 PMAny?
or @Nullable Object
, which is used as an intersection of T
and Result.Failure
.jossiwolf
01/26/2019, 3:58 PM