February 2018
Intermediate to advanced
350 pages
7h 35m
English
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>) { ...
Read now
Unlock full access