September 2019
Intermediate to advanced
462 pages
11h 3m
English
Creating functions, and methods, in Kotlin is refreshingly different from creating methods in Java. The greater flexiblity that Kotlin offers removes unnecessary ceremony when creating functions. Let’s start with short functions, explore type inference, and then look at defining parameters and multiline functions.
Kotlin follows the mantra “Keep it simple, stupid”—the KISS principle—to function definitions. Small functions should be simple to write, no noise, no fluff. Here’s one of the shortest functions you can write in Kotlin, followed by a call to it.
| | fun greet() = "Hello" |
| | |
| | println(greet()) |
Function declarations start with the keyword fun—Kotlin wants you to remember to have fun ...
Read now
Unlock full access