- Functional Kotlin
- Mario Arias Rivu Chakraborty
- 97字
- 2021-06-24 19:15:24
Data classes
Creating classes whose primary purpose is to hold data is a common pattern in Kotlin (is a common pattern in other languages too, think of JSON or Protobuff).
Kotlin has a particular kind of class for this purpose:
data class Item(val product: BakeryGood,
val unitPrice: Double,
val quantity: Int)
To declare data class, there are some restrictions:
- The primary constructor should have at least one parameter
- The primary constructor's parameters must be val or var
- Data classes can't be abstract, open, sealed, or inner
With these restrictions, data classes give a lot of benefits.
推薦閱讀
- SPSS數據挖掘與案例分析應用實踐
- MySQL數據庫管理實戰
- TypeScript Blueprints
- Building a Game with Unity and Blender
- Learning C++ Functional Programming
- Building Serverless Applications with Python
- Python時間序列預測
- NoSQL數據庫原理
- 零基礎Java學習筆記
- Scala for Machine Learning(Second Edition)
- Spring MVC+MyBatis開發從入門到項目實踐(超值版)
- Python Django Web從入門到項目實戰(視頻版)
- ASP.NET jQuery Cookbook(Second Edition)
- Learning PrimeFaces Extensions Development
- Perl 6 Deep Dive