Bird
0
0

Identify the error in this Kotlin code:

medium📝 Debug Q6 of 15
Kotlin - Null Safety
Identify the error in this Kotlin code:
val name: String? = "Kotlin"
name.let { println(it.length) }
ACannot use let with nullable types
BNo error, code runs fine
CIncorrect lambda syntax
DMissing safe call operator before let
Step-by-Step Solution
Solution:
  1. Step 1: Check safe call usage on nullable variable

    name is nullable, but let is called without safe call ?..
  2. Step 2: Understand consequence

    Calling let directly on nullable can cause NullPointerException if name is null.
  3. Final Answer:

    Missing safe call operator before let -> Option D
  4. Quick Check:

    Nullable variable needs ?. before let [OK]
Quick Trick: Always use ?.let on nullable variables to avoid errors [OK]
Common Mistakes:
MISTAKES
  • Calling let without safe call on nullable
  • Assuming let handles null automatically
  • Confusing let syntax with other functions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes