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

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.

主站蜘蛛池模板: 嵩明县| 临泽县| 广丰县| 乌鲁木齐市| 莎车县| 镇沅| 深水埗区| 开鲁县| 鸡泽县| 吉木乃县| 方城县| 武义县| 太谷县| 英超| 廊坊市| 儋州市| 大田县| 翼城县| 新闻| 成武县| 朝阳市| 兰州市| 仪征市| 土默特右旗| 柯坪县| 邢台市| 襄垣县| 开原市| 怀仁县| 曲阳县| 安义县| 鹤壁市| 平武县| 阜新| 堆龙德庆县| 平和县| 循化| 沂水县| 华阴市| 叙永县| 伊春市|