- Functional Kotlin
- Mario Arias Rivu Chakraborty
- 156字
- 2021-06-24 19:15:21
Classes
Classes are the foundational type in Kotlin. In Kotlin, a class is a template that provides a state, a behavior, and a type to instances (more on that later).
To define a class, only a name is required:
class VeryBasic
VeryBasic is not very useful, but is still a valid Kotlin syntax.
The VeryBasic class doesn't have any state or behavior; nonetheless, you can declare values of type VeryBasic, as shown in the following code:
fun main(args: Array<String>) {
val basic: VeryBasic = VeryBasic()
}
As you can see, the basic value has a VeryBasic type. To express it differently, basic is an instance of VeryBasic.
In Kotlin, types can be inferred; so, the previous example is equivalent to the following code:
fun main(args: Array<String>) {
val basic = VeryBasic()
}
By being a VeryBasic instance, basic has a copy of the VeryBasic type's state and behavior, namely, none. So sad.
推薦閱讀
- Spring Cloud Alibaba微服務架構設計與開發實戰
- 軟件架構設計:大型網站技術架構與業務架構融合之道
- Microsoft Dynamics 365 Extensions Cookbook
- Python數據分析(第2版)
- Mastering Android Development with Kotlin
- ExtJS高級程序設計
- Getting Started with Eclipse Juno
- Swift 4從零到精通iOS開發
- 開源項目成功之道
- Go語言開發實戰(慕課版)
- 從Excel到Python數據分析:Pandas、xlwings、openpyxl、Matplotlib的交互與應用
- 交互式程序設計(第2版)
- Oracle 12c從入門到精通(視頻教學超值版)
- JavaScript編程精解(原書第2版)
- 軟件測試技術