October 2018
Intermediate to advanced
370 pages
9h 15m
English
Kotlin makes it possible to assign a value to a parameter in the function declaration. If the function is invoked without passing a value, then the compiler automatically assigns a default value to it. The hello function prints Hello Kotlin if no value is passed to the function:
fun hello(message : String = "Kotlin") : Unit{ println("Hello $message")} fun main (args: Array<String>) { hello() hello("World")}
The default argument is a very helpful feature in many situations. For example, consider a situation in which we are writing a currency exchange function that converts dollars into another currency and applies service charges on the conversion:
fun currencyExchange(dollar: Double, currencyRate: Double, ...
Read now
Unlock full access