Kotlin allows function parameters to specify default values, which are automatically applied when the corresponding arguments are omitted during a function invocation. This mechanism is resolved at compile-time and reduces boilerplate by eliminating the need for explicit method overloading.Documentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
Syntax
Default values are defined by appending the assignment operator (=) and the value expression to the parameter declaration.
Evaluation Mechanics
Default parameter expressions are evaluated at call time (on each invocation), but the evaluation occurs within a compiler-generated synthetic method at the declaration site. This distinction means that default expressions are evaluated in the lexical scope of the declaration, allowing them to accessprivate members of the enclosing class or file, which would be inaccessible if they were evaluated at the call site.
Argument Resolution Rules
Trailing Default Parameters If default parameters are positioned at the end of the parameter list, callers can omit them using standard positional arguments.Inheritance and Overriding
When overriding a method that declares default parameters, the overriding method inherits the default values from the base type. The overriding signature must omit the default value declarations; redefining them is prohibited by the compiler to prevent ambiguity.Java Interoperability (@JvmOverloads)
Because the Java language does not natively support default parameters, a Kotlin function with default parameters is exposed to Java as a single method signature requiring all arguments.
To expose overloaded methods to Java callers, the @JvmOverloads annotation must be applied. This instructs the Kotlin compiler to generate a sequence of overloaded methods, dropping one default parameter at a time from right to left.
Master Kotlin with Deep Grasping Methodology!Learn More





