Bird
0
0

Why does Kotlin's when expression provide more power than a traditional switch statement?

hard📝 Conceptual Q10 of 15
Kotlin - Control Flow as Expressions
Why does Kotlin's when expression provide more power than a traditional switch statement?
AIt supports arbitrary boolean conditions and type checks
BIt only supports integer values like switch
CIt requires all cases to be constants
DIt cannot be used as an expression
Step-by-Step Solution
Solution:
  1. Step 1: Compare when with traditional switch

    Traditional switch supports only constants and limited types.
  2. Step 2: Identify when's advanced features

    when supports boolean conditions, ranges, type checks, and can be used as expression.
  3. Final Answer:

    It supports arbitrary boolean conditions and type checks -> Option A
  4. Quick Check:

    when is more powerful due to flexible conditions = It supports arbitrary boolean conditions and type checks [OK]
Quick Trick: when supports conditions and types beyond switch [OK]
Common Mistakes:
MISTAKES
  • Thinking when is limited like switch
  • Ignoring boolean conditions support
  • Assuming when can't be expression

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes