November 2018
Intermediate to advanced
388 pages
9h 5m
English
Constructors are used to initialize class properties. As in Java, a constructor is a special member function that is invoked when an object is instantiated. However, they work slightly different in Kotlin.
In Kotlin, there are two constructors:
The primary constructor is part of the class header. Here's an example:
class User() {}
The block of code surrounded by parentheses is the primary constructor. Consider the following code for 14a_PrimaryConstructor.kts:
class User(var firstName: String, var lastName: String) {}val user = User("Norman", "Lewis")println("First Name= ...Read now
Unlock full access