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

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.

主站蜘蛛池模板: 江华| 玉林市| 汉川市| 雅江县| 上林县| 长岛县| 新余市| 时尚| 资源县| 隆尧县| 高陵县| 新泰市| 阳泉市| 沐川县| 富锦市| 沧源| 潜江市| 平武县| 龙岩市| 都江堰市| 务川| 隆尧县| 历史| 宿松县| 义乌市| 平阴县| 东辽县| 东台市| 寿宁县| 如东县| 曲麻莱县| 乌拉特中旗| 苗栗县| 靖远县| 唐海县| 河东区| 贞丰县| 湘潭市| 瓦房店市| 文成县| 凤山市|