Bird
0
0

Why does Kotlin require parentheses around variables in destructuring declarations during collection iteration?

hard📝 Conceptual Q10 of 15
Kotlin - Collections Fundamentals
Why does Kotlin require parentheses around variables in destructuring declarations during collection iteration?
ATo specify variable types explicitly
BTo clearly group variables as a single destructuring unit
CTo indicate variables are mutable
DTo separate variables from the collection name
Step-by-Step Solution
Solution:
  1. Step 1: Understand destructuring syntax rules

    Parentheses group variables so Kotlin knows they belong together as one destructuring pattern.
  2. Step 2: Clarify why grouping is needed

    This avoids confusion with multiple variables and separates them from the collection being iterated.
  3. Final Answer:

    To clearly group variables as a single destructuring unit -> Option B
  4. Quick Check:

    Parentheses group destructured variables [OK]
Quick Trick: Parentheses group variables in destructuring [OK]
Common Mistakes:
MISTAKES
  • Thinking parentheses declare mutability
  • Assuming parentheses separate variables from collection
  • Believing parentheses specify types

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes