官术网_书友最值得收藏!

  • 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.

主站蜘蛛池模板: 水城县| 贞丰县| 阿拉尔市| 广水市| 宣化县| 通化市| 辽阳市| 睢宁县| 石景山区| 分宜县| 海林市| 阿合奇县| 和静县| 堆龙德庆县| 阿克陶县| 遵义市| 古田县| 南涧| 黄梅县| 塔城市| 汉沽区| 南康市| 邯郸县| 棋牌| 长寿区| 东乌珠穆沁旗| 晴隆县| 新宾| 新余市| 京山县| 轮台县| 定安县| 平罗县| 天长市| 邵武市| 扎囊县| 宜州市| 恭城| 堆龙德庆县| 普安县| 平度市|