From the course: Intermediate Kotlin for Android Developers

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Understanding lambdas

Understanding lambdas

From the course: Intermediate Kotlin for Android Developers

Start my 1-month free trial

Understanding lambdas

- [Instructor] Kotlin is all about lambdas, so let's take a closer look at why their use helps us to write concise code. We're going to start by reviewing their syntax, then how they can be passed as function parameters, and finally, how to use them with Java functional interfaces. This is a lambda. Let's break it down piece by piece. On the left side of the equal sign is the type of the lambda. In this case, it takes in an integer and returns a Boolean as its value. It's important to understand this syntax, although in practice, the type of the lambda is not often seen in code. On the other side of the equal sign is the expression. It always has opening and closing curly braces. This is what you'll see most often when working with lambda expressions. On the left side of the arrow is a listing of the parameters to the lambda. In this case, there's only one, and it's of type integer. On the right side of the arrow is the lambda's body. This is the piece of work that this lambda will…

Contents