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.

Review nullability

Review nullability

From the course: Intermediate Kotlin for Android Developers

Start my 1-month free trial

Review nullability

- [Instructor] Now let's take a look at nullability in Kotlin. This is what helps us to avoid null pointer exception errors in our code. So we're here inside of the nullability file, in the test folder. Now as you can see, we have several test methods that we're going to fill in, which will help us to better understand how the Kotlin language protects us from nulls in our code. So the first thing we're going to do is create a function called double string that would duplicate a string's contents here on line five. So just as usual, we start with the fun keyword, it's going to be called doubleString, we're going to pass in a string for the parameter, and we're going to return another string, which is the same one doubled. So this is just going to be the string that we receive, and then we'll use the repeat function from the Kotlin standard library and we'll supply the number two because we want it twice. Now notice that when we declare our string parameter, we don't have a question…

Contents