https://kotlinlang.org logo
Title
r

robstoll

12/30/2018, 11:40 PM
is it somehow possible to deal with the following problem.
interface I1{ fun foo(f: (Int) -> Int) }
interface I2{ fun foo(f: (String) -> String) }
class A: I1, I2{
  override fun foo(f: (Int) -> Int){}
  override fun foo(f: (String)-> String){} //same JVM signature
}
p

Pavlo Liapota

12/30/2018, 11:52 PM
Seems it only works for global functions
h

hudsonb

12/31/2018, 12:11 AM
This has bit me a number of times, AFAIK there's no way around it. Be awesome if
@JvmName
could be used as a work around (I havent tried it). We need a
@Mangle
annotation or something that will mangle it for us on the Java side when we don't care about being callable from the Java side of things.
👍 1
c

Czar

12/31/2018, 7:48 AM
This works for me:
interface I1 {
	fun foo(l: (Int) -> Int): Int
}

interface I2 {
	fun foo(l: (String) -> String): String
}

class A : I1, I2 {
	override fun foo(l: (Int) -> Int): Int = l(1)
	override fun foo(l: (String) -> String): String = l("a")
}

fun test() {
	println(A().foo { p: Int -> p * 2 })
	println(A().foo { p: String -> p + p })
}
I guess problem is only there if the return type is the same.
r

robstoll

12/31/2018, 9:22 AM
Ah sorry, return type should have been the same