August 2017
Intermediate to advanced
440 pages
10h
English
Kotlin allows defining functions in many contexts. We can define functions at the top level, as members (inside class, interface, and so on), and inside other functions (local function). Consider the following example of the definition of a local function:
fun printTwoThreeTimes() {
fun printThree() { // 1
print(3)
}
printThree() // 2
printThree() // 2
}
Elements accessible inside local functions don't have to be passed from enclosing functions as arguments because they are accessible directly. For example:
fun loadUsers(ids: List<Int>) { var downloaded: List<User> ...Read now
Unlock full access