0

I just can't understand why it is possible to extend function type in kotlin ? And then why we can't extend String? then, which is also a type.

interface CustomFunctionType : () -> Unit {
// this is possible, buy how?
}
abhi
  • 961
  • 9
  • 13
  • [`Function`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-function.html) is interface and hence open by default. While classes are final by default. – Animesh Sahu May 31 '20 at 14:28
  • so you mean that lambda is also a Function as well. Right ? – abhi May 31 '20 at 14:50
  • A lambda is `Function` in JVM bytecode, you can try to decompile to Java for a better view. For example `(Int) -> Int` is `Function1` which is `interface Function: Function {...}` again inherited from `Function` so yeah, this is hierarchy. – Animesh Sahu May 31 '20 at 14:56
  • String is a final class. Functional declarations are not final. They are like interfaces, which are never final. – Tenfour04 May 31 '20 at 15:26

0 Answers0