https://kotlinlang.org logo
Title
r

rahulsom

05/19/2017, 2:24 AM
I have this java interface
public interface AggregateType<AggregateIdT> {
    AggregateIdT getId();
}
I wrote this in my kotlin class
data class Patient(val id: String, val identifier: String): AggregateType<String>
I'm assuming that kotlin would provide me a
getId()
method. However, I get this error:
Class 'Patient' must be declared abstract or implement abstract member public abstract fun getId(): String!
When I do try to implement it like this:
data class Patient(val id: String, val identifier: String): AggregateType<String> {
    override fun getId() = id
}
I get a Platform Declaration clash.
b

blakelee

05/19/2017, 5:35 AM
rahulsom: Because you have a data class, the getter for id is getId of type string. Because you have a data class, your patient code already looks like this:
class Patient(val id: String, val identifier: String) {
    fun getId() = id //This is of type string
    //no set because it's immutable
    fun getIdentifier() = identifier
}
adding the interface would make it look like this I believe
class Patient(val id: String, val identifier: String) : AggregateType<String> {
    fun getId() = id //This is of type string
    override fun getId() = id //Now there are two functions named getId with the same signature
    //no set because it's immutable
    fun getIdentifier() = identifier
}