January 2019
Intermediate to advanced
392 pages
10h 11m
English
To define a function in Kotlin, you have to use the fun keyword, as follows:
fun firstClass() { println("First class function")}
The preceding snippet demonstrates that we can declare functions as first class citizens. We can also define functions as class members, as follows:
class A { fun classMember() { println("Class member") }}
A local function is a function that is declared in another one, as follows:
fun outer() { fun local() { println("Local") } local()}
In the preceding snippet, the local function is declared inside of the outer function. The local functions are only available in the scope of a function where they were declared. This approach can be useful if we want to avoid duplicate code inside of a function.
This ...
Read now
Unlock full access