2017-08-24 36 views
-3

Kotlin我可以這樣寫:數據類接口

interface KeyMapperService { 
interface Add { 
    data class Success(val key: String, val link: String): Add 
    data class AlreadyExist(val key: String): Add 
} 

interface Get { 
    data class Link(val link: String): Get 
    data class NotFound(val key: String): Get 
} 

    fun add(key: String, link: String): Add 

    fun getLink(key: String): Get 
} 

這將如何代碼看起來像Java中?我不明白。

+0

的IntelliJ有科特林反編譯。 – Moira

回答

2

這是科特林文件轉換成Java的直接轉換:

interface KeyMapperService { 
 
    interface Add { 
 
     class Success implements Add { 
 
      Success(String key, String link){} 
 
     } 
 

 
     class AlreadyExist implements Add { 
 
      AlreadyExist(String key){} 
 
     } 
 
    } 
 

 
    interface Get { 
 
     class Link implements Get{ 
 
      Link(String link){} 
 
     } 
 

 
     class NotFound implements Get{ 
 
      NotFound(String key){} 
 
     } 
 
    } 
 

 
    public Add add(String key, String link); 
 

 
    public Get getLink(String key); 
 
}