Functions.kt

for the sake of interest, I went to the sources of the kotlin and found there a file with the declared interfaces of 22 functions (function of 1 variable, 2, …22). It became interesting to know why this is the case and why to create such interfaces at all
https://upsource.jetbrains.com/kotlin/file/kotlin-ultimate-4bd8a6add94251ec73a10820ee7e55b0a21d04d6/libraries/stdlib/jvm/runtime/kotlin/jvm/functions/Functions.kt

When you use a function type, it is just syntactic sugar for using one of those interfaces.

  • ( ) -> R becomes Function< R >
  • ( P ) -> R becomes Function< P, R >
  • etc
1 Like