Long story short: having C# experience with explicit interfaces implementation, I tried to do the same on Kotlin and failed (or didn't find a way yet). Situation:
interface IProblem<T> {
fun solve(t: T)
}
class Puzzle: IProblem<Int>, IProblem<Any> {
override fun solve(t: Int) {
}
override fun solve(t: Any) {
}
}
As you can see, I have a class which I plan to have as an implementation for the same generic interface applied twice, with two different types T inside. For simplicity, let say they're Int
and Any
(it doesn't matter, they're just not the same, nor descendant/ancestor to each other).
So, I would expect I can explicitly say "hey, this solve()
method is for IProblem<Int>
and another solve()
is for IProblem<Any>
. Surprisingly, all I can get is IDE claiming that two methods have the same JVM signature.
Am I correct there is no such thing as explicit interface implementation in Kotlin and I have to re-think my design? I would imagine something like that:
class Puzzle: IProblem<Int>, IProblem<Any> {
override fun IProblem<Int>.solve(t: Int) {
}
override fun IProblem<Any>.solve(t: Any) {
}
}