Skip to main content
Positional parameters (or positional arguments) refer to the default mechanism of passing arguments to a function, method, or constructor where the mapping between the provided argument and the receiving parameter is determined strictly by their sequential order (index) in the function signature. The compiler binds the first argument to the first parameter, the second to the second, and so forth, evaluating them from left to right.

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.
In the invocation above, the binding occurs via index mapping:
  • Index 0 ("127.0.0.1") binds to host: CharSequence
  • Index 1 (443) binds to port: Number
  • Index 2 (true) binds to secure: 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.
To skip 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.
Interaction with 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