November 2018
Intermediate to advanced
388 pages
9h 5m
English
Default values to the arguments is a nice way for an API to evolve. If we already have a function with two arguments and we need a third argument, we can make the transition easy by making use of default values to arguments. The existing code still works and, at the same time, we can invoke a function with new arguments. Default values to arguments make the API simple and expressive.
Let's write an example to provide a default value to an argument to the function.
Consider the code for 6e_DefaultArguments.kts:
fun welcome(name: String, msg:String = "Hey") { println("$msg $name")}welcome("Bob", "hello")welcome("Berry")
In this case, we are not providing the second argument, msg, to the welcome() function. It therefore uses ...
Read now
Unlock full access