How could one implement multiple interfaces with same property name?

It just came to my mind, when I was following the Kotlin Koans
and trying to implement multiple interfaces Iterable<MyDate>, ClosedRange<MyDate>
like this

class DateRange(override val start: MyDate, override val endInclusive: MyDate) : Iterable<MyDate>, ClosedRange<MyDate> {
    override operator fun iterator(): Iterator<MyDate> {
        return DateIterator(this)

Here there wasn’t any problem, but if there were multiple interfaces that needs to be implemented having the same property name, how could it be implemented?

I did find this in the documentation,
but this didn’t solve my question.

If it makes sense, a single method can do. (requires arguments to be the same and the 2 api “contacts” to be compatible).

Otherwise you can’t :frowning:

The C# solution is to use explicit interface implementation, but that doesn’t exist in Java/Kotlin. This rarely happens though.

So does it mean that in Kotlin if this happens, we can’t implement it? Or is there some other workaround?

Yeah it would mean you can’t implement both. The workaround really depends on what you’re doing and what the interfaces are being used for (so I don’t have a general-purpose workaround), but you can almost always come up with another way of accomplishing what you want. The solution might even be to create two separate classes for the two conflicting interfaces, and have one adapt the other (with the adapter design pattern).

I see. Thanks for the explanation :slight_smile: