Edoardo Luppi
07/02/2023, 4:06 PMpublic interface ZDeferred<out T> {
public fun <S> then(thenFn: (T) -> S): ZDeferred<S>
}
Notice the thenFn: (T) -> S
It seems impossible to use from the Java side.
Any advice?Adam S
07/02/2023, 4:21 PMZDeferredExample
?Edoardo Luppi
07/02/2023, 4:31 PMpublic interface ZDeferredExample<out T> {
public fun <S> then(thenFn: (T) -> S): ZDeferredExample<S>
}
Edoardo Luppi
07/02/2023, 4:31 PMAdam S
07/02/2023, 4:37 PMAdam S
07/02/2023, 4:39 PMEdoardo Luppi
07/02/2023, 4:39 PMZDeferred
is in commonMain
Adam S
07/02/2023, 4:48 PMClass ‘Example’ must either be declared abstract or implement abstract method ‘then(Function1<? super T, ? extends S>)’ in ‘ZDeferred’
Adam S
07/02/2023, 4:48 PMAdam S
07/02/2023, 4:49 PMbuild.gradle.kts
kotlin {
jvm {
withJava()
@Suppress("OPT_IN_USAGE")
mainRun {
mainClass.set("Example")
}
}
}
Adam S
07/02/2023, 4:50 PMsrc/jvmMain/java/Example.java
file
import kotlin.jvm.functions.Function1;
import org.jetbrains.annotations.NotNull;
public class Example<T> implements ZDeferred<T> {
public static void main(String[] args) {
System.out.println("blah");
}
@NotNull
@Override
public <S> ZDeferred<S> then(@NotNull Function1<? super T, ? extends S> thenFn) {
return null;
}
}
Edoardo Luppi
07/02/2023, 4:52 PMEdoardo Luppi
07/02/2023, 4:53 PMAdam S
07/02/2023, 4:54 PMEdoardo Luppi
07/02/2023, 4:55 PMAdam S
07/02/2023, 4:57 PM@JvmSuppressWildcards
or @JvmWildcard
might change anything
• https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.jvm/-jvm-suppress-wildcards/
• https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.jvm/-jvm-wildcard/Edoardo Luppi
07/02/2023, 4:58 PMAdam S
07/02/2023, 4:59 PMFirst time I see themhaha me too
Adam S
07/02/2023, 4:59 PMEdoardo Luppi
07/02/2023, 5:01 PMEdoardo Luppi
07/02/2023, 5:01 PMEdoardo Luppi
07/02/2023, 5:25 PMpublic actual interface ZDeferred<T> {
// Replace functions with Java-interoperable ones.
// This allows clients to avoid importing Kotlin's stdlib
public fun <S> then(thenFn: Function<T, S>): ZDeferred<S>
public fun <S> thenDeferred(thenFn: Function<T, ZDeferred<S>>): ZDeferred<S>
public fun <S> thenCatch(catchFn: Function<Throwable, S>): ZDeferred<S>
public fun <S> thenCatchDeferred(catchFn: Function<Throwable, ZDeferred<S>>): ZDeferred<S>
public fun thenFinally(thenFn: BiFunction<T?, Throwable, Unit>)
// @formatter:off
@JvmSynthetic public actual fun <S> then(thenFn: (T) -> S): ZDeferred<S>
@JvmSynthetic public actual fun <S> thenDeferred(thenFn: (T) -> ZDeferred<S>): ZDeferred<S>
@JvmSynthetic public actual fun <S> thenCatch(catchFn: (Throwable) -> S): ZDeferred<S>
@JvmSynthetic public actual fun <S> thenCatchDeferred(catchFn: (Throwable) -> ZDeferred<S>): ZDeferred<S>
@JvmSynthetic public actual fun thenFinally(thenFn: (T?, Throwable?) -> Unit)
@JvmSynthetic public actual suspend fun await(): T
// @formatter:on
}