Hi how to fix this issue in kotlin, I want to assign sum function at var fn, but it gives error.
Overload resolution ambiguity. All these functions match
fun main(args:Array<String>) {
println(sum(2.0,3.0))
println(power(2.0,3.0))
var fn=::sum
}
fun sum(a:Double, b:Double):Double{
return a b
}
fun power(a:Double, b:Double):Double{
return a.pow(b)
}
CodePudding user response:
There is no problem with your above code - it compiles properly. If you have more sum()
functions in your code, e.g. for summing integers or other number types, then you can choose from them by providing the expected type to the compiler:
var fn: (Double, Double) -> Double = ::sum