

Kotlin uses a keyword called null to represent the absence of a value. When a variable does not have a value inside of it, we’ll say that the value is absent.

When a variable has a value inside of it, we’ll say that the value is present.So we want a bucket where we can either put a value inside of it, or leave it empty. When the guest leaves a rating, the bucket needs to contain that value, but when they forget to rate it, that bucket needs to be empty. For example, a stars bucket contains an Int, like the number 5:įor the CoffeeReview class, we need a stars bucket that might or might not have a value in it. In other words, we’ve always had something inside that bucket. In all the code that we’ve written so far, we’ve created variables that contain a value. How can he do that?Īs you might recall from Chapter 1, a variable is like a bucket that holds a value. Instead, he needs a way to tell Kotlin that they didn’t leave a star rating at all. When someone doesn’t leave a star rating, then James doesn’t want to show a zero-star rating on the screen. James realized that a zero-star rating is not the same thing as having no star rating. He thought that his solution would work well, but when the guests saw the review, they thought, “Wow, if Lucy didn’t like the coffee, maybe it’s not good.

This is what showed on the screen: Latest coffee reviews Printing the coffee reviews to the screen
