Which of the following is a valid requirement for a Kotlin function to be declared as infix?
easy📝 Conceptual Q2 of 15
Kotlin - Functions
Which of the following is a valid requirement for a Kotlin function to be declared as infix?
AIt must be a private function inside a class
BIt must return Unit and have no parameters
CIt must be a member function or an extension function with a single parameter
DIt must be a top-level function with multiple parameters
Step-by-Step Solution
Solution:
Step 1: Recall infix function requirements
An infix function must be a member or extension function with exactly one parameter.
Step 2: Match options with this rule
Only It must be a member function or an extension function with a single parameter matches this rule; others violate parameter count or visibility rules.
Final Answer:
It must be a member function or an extension function with a single parameter -> Option C
Quick Check:
Infix function requirements = Single parameter member/extension function [OK]
Quick Trick:Infix functions need exactly one parameter and be member or extension [OK]
Common Mistakes:
MISTAKES
Allowing multiple parameters
Thinking top-level functions can be infix
Assuming private visibility is required
Master "Functions" in Kotlin
9 interactive learning modes - each teaches the same concept differently