From the course: Build Spring Boot Apps with the Kotlin Programming Language

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

The let function

The let function

- [Instructor] Before we go on, I'd actually like to just point out another compiler warning which is very similar to the one we just had. You will get it with an IF statement, so I suppose it's relevant, although this is a little bit of a tangent from the main thing that we are learning about. In order to construct a case where this could happen, we need to have a var variable, a variable that is mutable. So let's create a mutable variable within our KotlinPerson class. I think we'll do this up here, and let's say what is their favorite color. I'm spelling favorite here the American way so apologies to our British listeners who'd like to put the letter u in there, and I'd like to say that that is going to be a string. In fact, it's going to be a nullable string and we're going to set it initially to have the value of null just so that it will compile. Okay, so I now want to create a method which is going to use this favoriteColor object. So let's say a method called, or a function…

Contents