Consider this class with two functions, one with Int
argument, the other with a generic one:
class C<K, V> {
// ...
operator fun f(index: Int): Pair<K, V> = ...
operator fun f(key: K): V = ...
}
When it is parameterized as C<Int, SomeType>
, K
is Int
, and both functions match the calls, resulting into an error:
val m = C<Int, SomeType>()
m.f(1)
Overload resolution ambiguity. All these functions match:
public final fun f(index: Int): SomeType
defined inC
public final fun f(key: Int): Pair<Int, SomeType>?
defined inC
How do I call whichever f
I want in this case?