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

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.

主站蜘蛛池模板: 澄迈县| 榆社县| 应城市| 九台市| 余庆县| 宁波市| 大新县| 静海县| 淳安县| 防城港市| 手游| 双鸭山市| 将乐县| 安仁县| 金昌市| 东城区| 岚皋县| 大邑县| 杭州市| 靖边县| 讷河市| 荔波县| 磐石市| 达孜县| 棋牌| 神农架林区| 嘉祥县| 沧州市| 普兰店市| 武汉市| 开阳县| 环江| 灵武市| 雷波县| 佛山市| 印江| 海伦市| 西林县| 灵川县| 安徽省| 资溪县|