- 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.
推薦閱讀
- C語言程序設(shè)計(jì)實(shí)踐教程(第2版)
- 深入理解Bootstrap
- 構(gòu)建移動(dòng)網(wǎng)站與APP:HTML 5移動(dòng)開發(fā)入門與實(shí)戰(zhàn)(跨平臺(tái)移動(dòng)開發(fā)叢書)
- 老“碼”識(shí)途
- D3.js 4.x Data Visualization(Third Edition)
- Getting Started with LLVM Core Libraries
- Integrating Facebook iOS SDK with Your Application
- Access 2010中文版項(xiàng)目教程
- HTML+CSS+JavaScript網(wǎng)頁設(shè)計(jì)從入門到精通 (清華社"視頻大講堂"大系·網(wǎng)絡(luò)開發(fā)視頻大講堂)
- Tableau Desktop可視化高級(jí)應(yīng)用
- Visual C++開發(fā)寶典
- Building Clouds with Windows Azure Pack
- C# 10核心技術(shù)指南
- 數(shù)據(jù)庫(kù)技術(shù)及應(yīng)用教程上機(jī)指導(dǎo)與習(xí)題(第2版)
- JavaScript程序設(shè)計(jì)基礎(chǔ)教程(慕課版)