- Kotlin for Enterprise Applications using Java EE
- Raghavendra Rao K
- 170字
- 2021-06-10 18:49:20
Named arguments
We can use a named argument to invoke a function and pass the arguments by naming them. Since the arguments are named, the order doesn't need to be maintained.
Let's take a look at the following example. Consider the code for 6f_NamedArguments.kts:
fun welcome(name: String, msg:String = "Hey") {
println("$msg $name")
}
welcome(msg = "How are you", name = "Mark")
The output is as follows:
We can also mix named arguments with arguments without a name. Consider the code for 6g_NamedArguments.kts:
fun welcome(name: String, msg:String = "Hey") {
println("$msg $name")
}
welcome("Joseph", msg = "Hi")
The output is as follows:
In this case, we invoked the function with one positional argument with the value Joseph and one argument named msg. When we are dealing with multiple arguments in a method, we can choose to send some arguments positionally by maintaining the order and to send others as named arguments. The language gives us the flexibility to invoke functions with type safety.
- Instant Node Package Manager
- Java加密與解密的藝術(第2版)
- Python Tools for Visual Studio
- Java系統化項目開發教程
- Active Directory with PowerShell
- C語言程序設計
- IBM Cognos Business Intelligence 10.1 Dashboarding cookbook
- Oracle GoldenGate 12c Implementer's Guide
- GameMaker Essentials
- ArcGIS for Desktop Cookbook
- INSTANT JQuery Flot Visual Data Analysis
- 數據結構:Python語言描述
- micro:bit軟件指南
- Internet of Things with Arduino Cookbook
- Getting Started with Hazelcast