it seems i can define 2 methods where the only dif...
# codereview
c
it seems i can define 2 methods where the only difference in signature is the number of parameters that their lambda takes:
Copy code
fun mf(method: suspend () -> String) {
}
fun mf(method: suspend (String) -> String) {
}
and i can call the method that takes one parameter just fine:
Copy code
mf({string->"string"})
but how can i call the other method?
Copy code
mf({"string"}) // fails with overload resolution ambiguity
s
where the only difference in signature is the number of parameters that their lambda takes
also I mean, sure, disparate arity means different function types, why wouldn’t that be overloadable?
c
thanks, so the solution is
mf({->"string"})
đź‘Ś 1
m
You have to look at the lambda type as a whole. So
() -> String
is a different type than
(String) -> String
, thus overloading is possible
c
sure. I just was not sure how to indicate which one i want to call at the call site.
m
Yeah that was tricky! I learned it from the linked thread as well