October 2019
Intermediate to advanced
434 pages
11h 54m
English
So far, we've been working with a Course class that takes in a courseTitle argument and then uses it to initialize a title property. This matches the pattern of initialization in Java; however, it can be simplified in Kotlin. You might notice that there is a direct 1:1 mapping from the primary constructor argument and eventually a property is assigned. This is not an uncommon occurrence in Java, and so Kotlin was designed to simplify this use case.
To illustrate the use of a primary constructor property, we'll once again start with our simple Course class example:
class Course(courseTitle: String) { val title = courseTitle}
We can then combine the courseTitle constructor argument and the title property into ...
Read now
Unlock full access