In common code I'm exposing an interface like ```p...
# multiplatform
e
In common code I'm exposing an interface like
Copy code
public 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?
a
can you also share
ZDeferredExample
?
e
@Adam S you can use this one:
Copy code
public interface ZDeferredExample<out T> {
  public fun <S> then(thenFn: (T) -> S): ZDeferredExample<S>
}
The result is the same
a
I don’t get the same error as you…
are Example.java and ZDeferred.kt in the same module? Is ZDeferred in commonMain or jvmMain?
e
@Adam S is that in a multiplatform project or a JVM-only project?
ZDeferred
is in
commonMain
a
just tried it with Example in jvmMain and ZDeferred in commonMain and I get the same error
Class ‘Example’ must either be declared abstract or implement abstract method ‘then(Function1<? super T, ? extends S>)’ in ‘ZDeferred’
However, it does seem to compile and run successfully. So I would guess it’s an IntelliJ issue
I’m using Kotlin 1.9.0-RC, and this jvm() config in
build.gradle.kts
Copy code
kotlin {
  jvm {
    withJava()
    @Suppress("OPT_IN_USAGE")
    mainRun {
      mainClass.set("Example")
    }
  }
}
and this
src/jvmMain/java/Example.java
file
Copy code
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;
  }
}
e
@Adam S probably just IJ! You're right! Seems I can also use `Function1`as a lambda in Java, which is great.
I'll post another related question in #javascript
a
it’s a good find, so it’d be worth making an issue on YouTrack :) https://youtrack.jetbrains.com/newIssue
e
Definitely going to open it. I'd like to get it working as intended lol
a
e
First time I see them. Need to check what they do
a
First time I see them
haha me too
but if there’s some annoying Kotlin/Java compatibility issue I always check https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.jvm/ just in case there’s something useful
e
Nope 😞 don't seem to make any difference. I guess if it works in the JVM side, it means there is an issue in how IJ reads stuff from common
It could be a simple indexing/stub problem
@Adam S how I've solved it for now
Copy code
public 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
}