- 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.
- AngularJS入門(mén)與進(jìn)階
- AWS Serverless架構(gòu):使用AWS從傳統(tǒng)部署方式向Serverless架構(gòu)遷移
- Programming ArcGIS 10.1 with Python Cookbook
- 精通搜索分析
- Python王者歸來(lái)
- Apache Kafka Quick Start Guide
- Unity 2D Game Development Cookbook
- 深入分布式緩存:從原理到實(shí)踐
- Learning OpenStack Networking(Neutron)(Second Edition)
- 好好學(xué)Java:從零基礎(chǔ)到項(xiàng)目實(shí)戰(zhàn)
- Flowable流程引擎實(shí)戰(zhàn)
- Building Serverless Architectures
- TypeScript圖形渲染實(shí)戰(zhàn):2D架構(gòu)設(shè)計(jì)與實(shí)現(xiàn)
- 少年小魚(yú)的魔法之旅:神奇的Python
- BackTrack 5 Cookbook