July 2018
Intermediate to advanced
400 pages
12h 14m
English
You have seen how to initialize properties or add logic to the initialization of properties in various ways – inline in a primary constructor, initialized at declaration, initialized in a secondary constructor, or initialized in an initializer block. It is possible for the same property to be referenced in multiple initializers, so the order in which they are executed is important.
To take a closer look, it is helpful to examine the resulting field initialization order and method invocations in the decompiled Java bytecode. Consider the following, which defines a Player class and constructs an instance of it:
class Player(_name: String, val health: Int) { val race = "DWARF" var town = "Bavaria" val name = _name ...Read now
Unlock full access