October 2019
Intermediate to advanced
434 pages
11h 54m
English
Another powerful feature of Kotlin functions are default parameter values. These allow us to specify a default value when defining any parameter. This value will then be used if the argument is not passed to the function invocation.
To define a default argument value, add = followed by the desired value after the type component of your parameter definition:
fun helloFunctions(greeting: String, name: String = "Kotlin") { println("$greeting $name")}
In this example, we've made "Kotlin" the default value for the name parameter. When helloFunctions is called with both arguments, the passed argument values will be used. However, if only the greeting is passed, then the default value of "Kotlin" will be used. The following ...
Read now
Unlock full access