How to implement interface properties with the same name and different type in Kotlin

Viewed 114

Any suggestions about how to make this code compilable?

interface I1 {
    val id: String
}
interface I2 {
    val id: Integer
}
class Test: I1, I2 {
    //???
}
1 Answers

I guess you can do this by generics.

class Test<T>{
val id: T? = null
}

And you can call this by

val test = Test<String>().id
val test01 = Test<Int>().id
Related