I have a simple factory pattern where the implementation is determined through overload resolution. Problem is that the Kotlin compiler complains with "Overload resolution ambiguity.." for the inline lambda.
class Foo(){
companion object Factory {
fun create(x: Int, f: (Int) -> Double) = 2.0
fun create(x: Int, f: (Int) -> Int) = 1
}
}
fun main(args:Array<String>){
val a = Foo.create(1,::fromDouble) //OK
val b = Foo.create(1,::fromInt) //OK
val ambiguous = Foo.create(1){i -> 1.0} //Overload resolution ambiguity?
}
fun fromDouble(int:Int) = 1.0
fun fromInt(int:Int) = 1
How does the Kotlin compiler resolve overload resolution and why is the inline lambda considered to be ambiguous?