Describe the problem
There is an error in the code below because the type of the fishFoodTreats variable is Int when it should be Int?. fishFoodTreats is defined as a non-null Int but the safe call operator ?. is intended for use with nullable types.
var fishFoodTreats = 6
fishFoodTreats = fishFoodTreats?.dec()
Here's a corrected version:
var fishFoodTreats: Int? = 6
fishFoodTreats = fishFoodTreats?.dec()
In which step of the codelab can this issue be found?
Lesson 2, 4: "Task: Learn about nullability"
Steps to reproduce?
Copy and paste
var fishFoodTreats = 6
fishFoodTreats = fishFoodTreats?.dec()
as shown in the lesson and run it in the Kotlin REPL.
Versions
IntelliJ IDEA 2024.2.4 (Ultimate Edition)
Describe the problem There is an error in the code below because the type of the
fishFoodTreats
variable isInt
when it should beInt?
.fishFoodTreats
is defined as a non-nullInt
but the safe call operator?.
is intended for use with nullable types.Here's a corrected version:
In which step of the codelab can this issue be found? Lesson 2, 4: "Task: Learn about nullability"
Steps to reproduce? Copy and paste
as shown in the lesson and run it in the Kotlin REPL.
Versions IntelliJ IDEA 2024.2.4 (Ultimate Edition)
Additional information None
codelab: kotlin-bootcamp