In Kotlin, how can I get around conflicts with inherited declarations when the enum class implements an interface?

I define an enumeration class that implements Neo4j RelationshipType:

enum class MyRelationshipType : RelationshipType {
    // ...
}

I get the following error:

Inherited platform declarations clash: The following declarations have the same JVM signature (name()Ljava/lang/String;): fun <get-name>(): String fun name(): String

I understand that the method name()from the class Enumand name()from the interface RelationshipTypehas the same signature. This is not a Java problem, but why is it a bug in Kotlin, and how can I get around it?

+4
source share
1 answer

this is bug-KT-14115 , even if you create a class enumto implement an interface that contains a function name(), it is rejected.

interface Name {
    fun name(): String;
}


enum class Color : Name;
       //   ^--- the same error reported

enum sealed, :

interface Name {
    fun name(): String;
}


sealed class Color(val ordinal: Int) : Name {
    fun ordinal()=ordinal;
    override fun name(): String {
        return this.javaClass.simpleName;
    }
    //todo: simulate other methods ...
};

object RED : Color(0);
object GREEN : Color(1);
object BLUE : Color(2);
+4

Source: https://habr.com/ru/post/1679287/


All Articles