October 2019
Intermediate to advanced
434 pages
11h 54m
English
After any primary constructor properties, the next initialization will occur in class-level property assignments and in initializer blocks. These will occur in the order in which they are defined within the class.
In the following snippet, we are initializing four properties, which we will examine to better understand the initialization sequence:
class Student(_firstName: String, val lastName: String) { val firstName = _firstName val id: String var nickname = "" init { id = generateStudentId(firstName, lastName) } val subjects:MutableList<String> = mutableListOf()}
In the preceding example, after lastName is initialized, the properties will be initialized in the following order:
Read now
Unlock full access