Introduction: Java has only the concept of methods, there is no concept of functions

Functions with Lambda closures

  • The characteristic syntax of a function
  • Nested function
  • Extension function
  • Lambda closure syntax
  • Higher-order functions
  • Inline function

Properties of a function

I mentioned before that you can have default values and things like that

Nested function

// Function nesting (normally not used) // purpose: 1. In some cases trigger recursion function 2. Funtaofun () {val STR = "function nested" funsay (count: Int = 10) { if (count > 0) { say(count -1) } } say() }Copy the code

Extension function

Funkotinmain.ref () {} funkotinmain.ref () {}Copy the code

Lambda closure

// Java8 lambda public static void lambdaFun() { Thread thread = new Thread(() -> { }); thread.start(); } --------------------------------------------- //kotlin lambda fun kotinFun() { //kotlin lambda //val thread = Thread({ -> val thread = thread ({}) thread.start()}Copy the code

** Note: ** I probably don’t use this much, so I’ll briefly mention it here, and I’ll add it later if necessary.

Higher-order functions

Definition: the argument to a function or lambda is another function or lambda.