12.10 Nullable Types and the let Function
Earlier in this chapter we looked at how the safe call operator can be used when making a call to a function belonging to a nullable type. This technique makes it easier to check if a value is null without having to write an if statement every time the variable is accessed. A similar problem occurs when passing a nullable type as an argument to a function which is expecting a non-null parameter. As an example, consider the times() function of the Int data type. When called on an Int object and passed another integer value as an argument, the function multiplies the two values and returns the result. When the following code is executed, for example, the value of 200 will be displayed within the console:
val firstNumber = 10
val secondNumber = 20
val result = firstNumber.times(secondNumber)
print(result)
The above example works because the secondNumber variable is a non-null type. A problem, however, occurs if the secondNumber...