Listing 6.7 and "Using safe calls with let" mismatch?

In the 4th paragraph on page 89, it says:

Run Tavern.kt with the reassignment to null commented out, then uncommented. When beverage is not null, let is invoked, capitalization happens, and the result is printed. When beverage is null, the contents of the let function are not evaluated, and beverage remains null.

But on the previous page 88, Listing 6.7, the commented out line

// beverage = null

is BELOW the code block which includes

beverage = readLine()?.let {

line, so it seems to be not possible to prevent the execution of the let block when it is uncommented.


:+1: I was going to raise this too. Is there an updated code sample we can use?

Thanks for producing this book, enjoying it so far!

1 Like


even if the line
beverage = null
would be above the block with
beverage = readLine()?.let {
it is not as simple as typing null or leave it blank while execution time to prevent the execution of the let block.
In the Kotlin standard library it says:
readLine(): Return the line read or null if the input stream is redirected to a file and the end of file has been reached.
Am i wrong here?