Bird
0
0

Why does Kotlin separate mutable and immutable collection interfaces instead of using a single interface with optional mutability?

hard📝 Conceptual Q10 of 15
Kotlin - Collections Fundamentals
Why does Kotlin separate mutable and immutable collection interfaces instead of using a single interface with optional mutability?
ATo reduce the number of collection classes
BBecause Kotlin does not support mutable collections
CTo enforce clear contracts and prevent accidental modification
DTo make all collections thread-safe by default
Step-by-Step Solution
Solution:
  1. Step 1: Understand design rationale

    Kotlin separates interfaces to clearly distinguish mutable from immutable collections.
  2. Step 2: Reason about benefits

    This separation helps prevent accidental changes and enforces contracts at compile time.
  3. Final Answer:

    To enforce clear contracts and prevent accidental modification -> Option C
  4. Quick Check:

    Separation enforces immutability contracts [OK]
Quick Trick: Separate interfaces clarify mutability intent [OK]
Common Mistakes:
MISTAKES
  • Thinking Kotlin lacks mutable collections
  • Assuming fewer classes is goal
  • Believing all collections are thread-safe

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes