Bird
0
0

Why does Kotlin restrict infix functions to have exactly one parameter and be member or extension functions?

hard📝 Conceptual Q10 of 15
Kotlin - Functions
Why does Kotlin restrict infix functions to have exactly one parameter and be member or extension functions?
ATo keep the syntax simple and readable like natural language expressions
BTo improve runtime performance by limiting parameters
CTo enforce strict type safety at compile time
DTo allow infix functions to be used only in top-level declarations
Step-by-Step Solution
Solution:
  1. Step 1: Understand Kotlin design goals for infix functions

    Kotlin restricts infix functions to one parameter and member/extension functions to keep calls simple and readable.
  2. Step 2: Evaluate options

    To keep the syntax simple and readable like natural language expressions matches this reasoning; others describe unrelated goals.
  3. Final Answer:

    To keep the syntax simple and readable like natural language expressions -> Option A
  4. Quick Check:

    Infix function restrictions = readability and simplicity [OK]
Quick Trick: Infix rules exist to keep code clean and readable [OK]
Common Mistakes:
MISTAKES
  • Thinking restrictions improve performance
  • Confusing with type safety enforcement
  • Believing infix functions must be top-level

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes