- Functional Kotlin
- Mario Arias Rivu Chakraborty
- 60字
- 2021-06-24 19:15:25
The copy() method
Sometimes, we want to reuse values from an existing instance. The copy() method lets us create new instances of a data class, overriding the parameters that we want:
val myItem = Item(myAlmondCupcake, 0.40, 5)
val mySecondItem = myItem.copy(product = myCaramelCupcake) //named parameter
In this case, mySecondItem copies unitPrice and quantity from myItem, and replaces the product property.
推薦閱讀
- 垃圾回收的算法與實現
- Practical Windows Forensics
- iOS編程基礎:Swift、Xcode和Cocoa入門指南
- SQL Server 2016數據庫應用與開發
- Test-Driven Development with Django
- Kubernetes源碼剖析
- Flowable流程引擎實戰
- Hands-On GUI Programming with C++ and Qt5
- 深入淺出Go語言編程
- Learning Ionic
- Mastering SciPy
- C Primer Plus(第6版)中文版【最新修訂版】
- ANSYS FLUENT 16.0超級學習手冊
- Swift編程實戰:iOS應用開發實例及完整解決方案
- HTML5+CSS3+JavaScript案例實戰