Bird
0
0

Identify the error in this Kotlin code snippet:

medium📝 Debug Q14 of 15
Kotlin - Collections Fundamentals
Identify the error in this Kotlin code snippet:
val data = listOf()
if (data.isEmpty) {
    println("No data")
}
AMissing parentheses after isEmpty
BlistOf<String>() cannot be empty
Cprintln syntax is incorrect
Ddata should be mutable
Step-by-Step Solution
Solution:
  1. Step 1: Check usage of isEmpty

    isEmpty is a function and must be called with parentheses: isEmpty().
  2. Step 2: Verify other parts of the code

    listOf() creates an empty list correctly, println syntax is correct, and mutability is not required for checking emptiness.
  3. Final Answer:

    Missing parentheses after isEmpty -> Option A
  4. Quick Check:

    Functions need parentheses even if no arguments [OK]
Quick Trick: Always add () when calling functions like isEmpty() [OK]
Common Mistakes:
MISTAKES
  • Using property syntax for functions
  • Thinking empty list creation is invalid
  • Assuming mutability is needed for checks

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes