- Kotlin Standard Library Cookbook
- Samuel Urbanowicz
- 119字
- 2021-07-23 19:05:53
How it works...
We've declared a default value for the initialSpeed parameter, equal to 0. Once we have a default value assigned, the initialSpeed parameter becomes an optional one. We can now omit it while invoking the function, as shown in the following example:
val displacement = calculateDisplacement(acceleration = 9.81f, duration = 1000)
Note that, if we are omitting some of the parameters and using their default values, we have to specify the values of the other parameters together with their names explicitly. This allows the compiler to map the values to the specific parameters. Of course, we are able to override the default value using the standard way:
val displacement = calculateDisplacement(10f, 9.81f, 1000)
推薦閱讀
- Arduino by Example
- Java入門很輕松(微課超值版)
- Learn WebAssembly
- Jupyter數(shù)據(jù)科學(xué)實(shí)戰(zhàn)
- 用戶體驗(yàn)增長:數(shù)字化·智能化·綠色化
- 圖數(shù)據(jù)庫實(shí)戰(zhàn)
- Julia 1.0 Programming Complete Reference Guide
- Django實(shí)戰(zhàn):Python Web典型模塊與項(xiàng)目開發(fā)
- Scala Functional Programming Patterns
- PHP項(xiàng)目開發(fā)全程實(shí)錄(第4版)
- 虛擬現(xiàn)實(shí)建模與編程(SketchUp+OSG開發(fā)技術(shù))
- Hands-On ROS for Robotics Programming
- Practical Linux Security Cookbook
- Python程序設(shè)計(jì)案例教程
- Node.js核心技術(shù)教程