Named arguments in functions

Kotlin functions can be invoked with the name of the arguments. As an example, consider the following function:

fun withNamedArguments(firstName : String, lastName : String) {
println("Hello Mr. $firstName, $lastName");
}

This function can be invoked as in the following code:

withNamedArguments(firstName = "Shazin", lastName = "Sadakath");

This is a really nice feature to enable good readability and reduce the number of errors.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.226.177.86