Skip to content

Instantly share code, notes, and snippets.

@dladukedev
Last active December 19, 2023 02:48
Show Gist options
  • Save dladukedev/e801176f8e8f08289e5e2f8be939b979 to your computer and use it in GitHub Desktop.
Save dladukedev/e801176f8e8f08289e5e2f8be939b979 to your computer and use it in GitHub Desktop.
Kotlin Function Reference Ambiguity
data class AdditionClass(val str: String, val num: Int) {
fun add(addStr: String): String {
return str + addStr
}
fun add(addNum: Int): Int {
return num + addNum
}
}
val addition = AdditionClass("Hello", 10)
// Compile Error!
val add = addition::add
// Success!
val addInt: (Int) -> Int = addition::add
// Still Compile Error!
val addString = addition::add as (String) -> String
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment