How to overcome “same JVM signature” error when implementing a Java interface?

后端 未结 9 1907
星月不相逢
星月不相逢 2020-12-13 16:55

With the code below, I am getting the following error in IntelliJ IDEA 13.1.6 and Kotlin plugin 0.11.91.AndroidStudio.3:

Platform declaration clash: The foll         


        
9条回答
  •  自闭症患者
    2020-12-13 17:39

    Another work-around is to declare the properties in an abstract Kotlin class, then write a small java class that extends KotlinClass and implements JavaInterface.

    // JavaInterface.java
    public interface JavaInterface {
        int getFoo();
        void setFoo(int value);
    }
    
    // KotlinClass.kt
    abstract class KotlinClass(open var foo : Int = 0) {
    }
    
    // JavaAdapter.java
    class JavaAdapter extends KotlinClass implements JavaInterface {
        // all code in KotlinClass, but can't implement JavaInterface there
        // because kotlin properties cannot override java methods.
    }
    

提交回复
热议问题