- Hands-On Design Patterns with Kotlin
- Alexey Soshin
- 128字
- 2021-06-25 20:49:25
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.
推薦閱讀
- 數(shù)據(jù)庫程序員面試筆試真題與解析
- TensorFlow Lite移動端深度學(xué)習(xí)
- Unity 2020 Mobile Game Development
- Swift 3 New Features
- 信息技術(shù)應(yīng)用基礎(chǔ)
- C#程序設(shè)計(jì)基礎(chǔ):教程、實(shí)驗(yàn)、習(xí)題
- Learning Zurb Foundation
- 青少年學(xué)Python(第1冊)
- Learning OpenStack Networking(Neutron)(Second Edition)
- 深入淺出React和Redux
- Android應(yīng)用案例開發(fā)大全(第二版)
- 輕松上手2D游戲開發(fā):Unity入門
- Django 3.0入門與實(shí)踐
- Test-Driven JavaScript Development
- Learning Perforce SCM