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

Data classes

Remember how Kotlin is all about productiveness? One of the most common tasks for Java developers is to create another Plain Old Java Object (POJO). If you're not familiar with POJO, it is basically an object that only has getters, setters, and an implementation of equals or hashCode methods.

This task is so common that Kotlin has it built into the language:

data class User (val username : String, val password : String)

This will generate a class with two getters and no setters (note the val part), which will also implement equals, hashCode, and clone functions in the correct way.

The introduction of data classes is one of the biggest improvements in reducing the amount of boilerplate in the language.

主站蜘蛛池模板: 阿拉善左旗| 运城市| 赤峰市| 逊克县| 丽水市| 颍上县| 青田县| 洛浦县| 武山县| 乌什县| 噶尔县| 九龙坡区| 方城县| 六安市| 聂荣县| 宁阳县| 永清县| 双辽市| 曲周县| 梁平县| 长治县| 苍溪县| 清水河县| 镇平县| 东源县| 海安县| 徐州市| 平邑县| 雷波县| 白河县| 怀仁县| 手游| 滦南县| 高尔夫| 西安市| 巴青县| 梓潼县| 西峡县| 寿阳县| 开远市| 遂溪县|