Syntax and Mechanics
When invoking a function using positional arguments, the types of the provided arguments must be assignable to (i.e., subtypes of) the declared parameter types at the corresponding indices.- Index
0("127.0.0.1") binds tohost: CharSequence - Index
1(443) binds toport: Number - Index
2(true) binds tosecure: Boolean
Rules and Constraints
Strict Left-to-Right Binding Positional arguments are always consumed strictly from left to right. You cannot skip a parameter positionally. If a function defines default values for its parameters, positional arguments will overwrite those defaults in sequential order.timeout and retries and only provide a value for log, positional arguments cannot be used; named arguments are required.
Mixing with Named Arguments
Kotlin allows mixing positional and named arguments in a single invocation. When doing so, positional arguments must maintain their exact sequential alignment with the function signature. Prior to Kotlin 1.4, all positional arguments had to precede the first named argument. As of Kotlin 1.4+, a named argument can appear anywhere in the sequence, provided the subsequent positional arguments remain in their correct absolute index slots.
vararg
When a function signature includes a vararg (variable number of arguments) parameter, positional arguments will be continuously absorbed by the vararg until the argument list ends or a named argument is encountered. If the vararg is not the final parameter in the signature, any parameters declared after it cannot be assigned using positional arguments.
Tired of Poor Kotlin Skills? Fix That With Deep Grasping!Learn More





