Kotlin / KEEP

Kotlin Evolution and Enhancement Process
Apache License 2.0
3.42k stars 362 forks source link

KMP Kotlin-to-Java direct actualization #391

Open nikitabobko opened 2 months ago

nikitabobko commented 2 months ago

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

kevin1e100 commented 1 month ago

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.

nikitabobko commented 1 month ago

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