2017-06-14 29 views
4

我定義實現枚舉類的Neo4j的RelationshipType在Kotlin中,當枚舉類實現接口時,如何解決繼承的聲明衝突?

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

我收到以下錯誤:

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

據我所知,無論是從Enumname()方法,並從name()方法RelationshipType接口具有相同的簽名。然而,這在Java中並不是問題,那麼爲什麼它在Kotlin中是錯誤的,我該如何解決它?

回答

4

它是一個bug-KT-14115即使你讓enum類實現接口含有name()功能被拒絕。

interface Name { 
    fun name(): String; 
} 


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

您可以通過使用sealed類,例如模擬enum類:

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);