Named parameters, default parameter values, variable parameters

1.1. Named Parameters

To make the code more readable, Kotlin allows you to use named parameters. That is, when a function is called, the name of the function’s parameters can be specified together to express the meaning and function of the parameters, but once you specify the name of one parameter, all subsequent parameters need to be named


1.2. Default Parameter values

You can specify default values for parameters when declaring functions to avoid creating overloaded functions


For this example, if the usual calling syntax dictates that the arguments are given in the order defined in the function declaration, only the last arguments can be omitted


If you use named parameters, you can omit any parameters that have default values, and you can pass in the desired parameters in any order


1.3. Variable parameters

Mutable arguments allow us to pack any number of arguments into an array and pass them to a function. Kotlin’s syntax differs from Java’s by declaring mutable arguments using the varage keyword instead

For example, the following function calls are all correct


Whereas in Java, arrays can be passed directly to mutable arguments, Kotlin requires explicit unpacking of arrays so that each array element can be called as a separate argument in a function. This feature is called the expansion operator, and is used by prepping array arguments with a *


1.4. Local functions

Kotlin supports nesting functions within functions, and the nested functions are called local functions