August 2017
Intermediate to advanced
440 pages
10h
English
The simplest way to define anonymous functions in Kotlin is by using a feature called lambda expressions. They are similar to Java 8 lambda expressions, but the biggest difference is that Kotlin lambdas are actually closures, so they allow us to change variables from the creation context. This is not allowed in Java 8 lambdas. We will discuss this difference later in this section. Let's start with some simple examples. Lambda expressions in Kotlin have the following notation:
{ arguments -> function body }
Instead of return, the result of the last expression is returned. Here are some simple lambda expression examples:
Read now
Unlock full access