Reputation: 28574
I have a question. Is there any there any other way to fix this code than adding @JvmName
?
class Test() {
fun <T> apply(calc: (String, List<Double>, Double, Double) -> T): T {
return calc("a", listOf(), 1.2, 3.4)
}
fun <T> apply(calc: (String, Double, Double, Double) -> T): T {
return calc("a", 1.2, 3.4, 5.6)
}
}
The above code makes the following error:
Error:(375, 9) Kotlin: Platform declaration clash: The following declarations have the same JVM signature (apply(Lkotlin/jvm/functions/Function4;)Ljava/lang/Object;):
fun <T> apply(calc: (String, Double, Double, Double) -> T): T defined in Sample.Test
fun <T> apply(calc: (String, List<Double>, Double, Double) -> T): T defined in Sample.Test
Upvotes: 3
Views: 364
Reputation: 28574
It looks like there is no way, as the generic code generated by Kotlin uses the Function4 as the argument type. It is an interface of 4 generic arguments, so regardless the types, all look the same.
/** A function that takes 4 arguments. */
public interface Function4<in P1, in P2, in P3, in P4, out R> : Function<R> {
/** Invokes the function with the specified arguments. */
public operator fun invoke(p1: P1, p2: P2, p3: P3, p4: P4): R
}
Upvotes: 4