KEEP icon indicating copy to clipboard operation
KEEP copied to clipboard

KMP Kotlin-to-Java direct actualization

Open nikitabobko opened this issue 1 year ago • 2 comments

This issue is for discussion of the proposed Kotlin-to-Java direct actualization. The full text of the proposal is here.

PR: https://github.com/Kotlin/KEEP/pull/392

nikitabobko avatar Sep 02 '24 08:09 nikitabobko

I'm a little unclear whether @KotlinActual annotations will be needed on methods and nested classes of classes that have that annotation? So for instance:

// COMMON
expect class Foo {
  fun bar()

  class Quux {}
}
@KotlinActual
public class Foo {
    @KotlinActual // (1) needed?
    public void bar() {...}

    public void baz() {...}

    @KotlinActual // (2) needed?
    public static class Quux {}
}

It would seem tedious to have to annotate (1) in particular, i.e., every method corresponding to a declaration in the expected class.

kevin1e100 avatar Sep 17 '24 02:09 kevin1e100

I'm a little unclear whether @KotlinActual annotations will be needed on methods and nested classes of classes that have that annotation?

Yes, both (1) and (2) will be needed. @KotlinActual in Java works similarly to actual keyword in Kotlin

It would seem tedious to have to annotate (1) in particular, i.e., every method corresponding to a declaration in the expected class.

I understand the concern. I agree that initially, it will be harder to commonize existing Java classes, but hopefully @KotlinActual will help in the long run with the error prevention and library maintenance https://github.com/Kotlin/KEEP/blob/kotlin-to-java-direct-actualization/proposals/kmp-kotlin-to-java-direct-actualization.md#actual-keyword-is-a-virtue

It's appealing to me that the annotation resembles actual keyword behavior

nikitabobko avatar Sep 17 '24 10:09 nikitabobko

The proposal makes no mention of object and companion object.

Are there technical limitations to expressing those? Would mirroring the same class and static instance holder structure with the annotation on both work?

JakeWharton avatar Feb 21 '25 04:02 JakeWharton

@JakeWharton expect object/expect companion object actualization to Java indeed goes beyond this proposal. Right now, it's a separate feature request https://youtrack.jetbrains.com/issue/KT-29882

nikitabobko avatar Feb 21 '25 10:02 nikitabobko