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

Destructuring methods

By convention, any instance of a class that has a series of methods named component1(), component2() and so on can be used in a destructuring declaration.

Kotlin will generate these methods for any data class:

val (prod: BakeryGood, price: Double, qty: Int) = mySecondItem

The prod value is initialized with the return of component1(), price with the return of component2() , and so on. Although the preceding example use explicit types, those aren't needed:

val (prod, price, qty) = mySecondItem

In some circumstances, not all values are needed. All unused values can be replaced by (_):

val (prod, _, qty) = mySecondItem
主站蜘蛛池模板: 东丰县| 班戈县| 横峰县| 武邑县| 隆德县| 芒康县| 桦南县| 武平县| 五大连池市| 璧山县| 日照市| 叶城县| 安国市| 林周县| 宝清县| 炉霍县| 柘城县| 襄汾县| 海南省| 樟树市| 工布江达县| 繁昌县| 牙克石市| 武宣县| 德阳市| 兴仁县| 临夏市| 兴和县| 正定县| 阜新市| 南丰县| 东乡县| 三明市| 利津县| 永城市| 长岛县| 牙克石市| 东源县| 德江县| 合山市| 永和县|