October 2018
Intermediate to advanced
370 pages
9h 15m
English
Kotlin makes it possible to specify the argument's name in a function call. This approach makes the function call more readable and reduces the chance to pass the wrong value to the variable, especially when all variables have the same data type. To understand the importance of this feature, let's take the previous example of currency conversion:
fun currencyExchange(dollar: Double, currencyRate: Double, charges: Double = 5.0): Double { var total = dollar * currencyRate var fees = total * charges / 100 total = total - fees return total }
The currencyExchange function takes three parameters of the Double type—dollar, target currency, and conversion charges:
fun main (args: Array<String>) { var total = currencyExchange(100.0, ...Read now
Unlock full access