google-developer-training / kotlin-bootcamp

Report issues with the Kotlin Bootcamp for Programmers codelab
7 stars 2 forks source link

Lesson 1.2 Kotlin Basics issue: Error in example code using ? operator #191

Open Paredes opened 1 year ago

Paredes commented 1 year ago

Hi, I found a error in: 4. Learn about nullability Specifically in Step 2 point 2, in the example code where show the use of ? operator

var fishFoodTreats = 6
fishFoodTreats = fishFoodTreats?.dec()

Generates the following:

error: type mismatch: inferred type is Int? but Int was expected fishFoodTreats = fishFoodTreats?.dec()

I believe that need to be:

var fishFoodTreats: Int? = 6
fishFoodTreats = fishFoodTreats?.dec()

Versions IntelliJ IDEA 2023.1.2 CE built on August 23, 2023 Windows 10

codelab: kotlin-bootcamp

Xronophobe commented 6 months ago

I was about to report it. The same course is also available at the Kotlin Bootcamp for Programmers 2: Kotlin basics where I bumped into this mistake.