September 2019
Intermediate to advanced
462 pages
11h 3m
English
Overloading of functions is common in Java and is the way to create functions that can take different number and type of arguments. That’s an option in Kotlin as well, but the feature of default arguments is a simpler and better way to evolve functions, though it requires recompilation as it breaks binary compatibility. Also, named arguments is a great way to create readable code. We’ll focus on those two features now.
Quickly glance at the greet() function we wrote earlier, repeated here for convenience.
| | fun greet(name: String): String = "Hello $name" |
| | |
| | println(greet("Eve")) //Hello Eve |
The greet() function has a hardcoded string "Hello", but what if we want to ...
Read now
Unlock full access