07-20-2023, 06:33 AM
I can't understand the following piece of Kotlin documentation:
The initializer, getter and setter are optional. Property type is optional
if it can be inferred from the initializer or from the base class member being overridden.
Examples:
var allByDefault: Int? // error: explicit initializer required, default
getter and setter implied
The only explanation of why the compiler requires explicit initializer here (at least the only explanation I can come up with) is that Kotlin does not have default values of properties. Is it right? If so, why? In other words: what is the difference between Kotlin properties and Java fields (which have default values) which doesn't allow us to have default values of properties?
The initializer, getter and setter are optional. Property type is optional
if it can be inferred from the initializer or from the base class member being overridden.
Examples:
var allByDefault: Int? // error: explicit initializer required, default
getter and setter implied
The only explanation of why the compiler requires explicit initializer here (at least the only explanation I can come up with) is that Kotlin does not have default values of properties. Is it right? If so, why? In other words: what is the difference between Kotlin properties and Java fields (which have default values) which doesn't allow us to have default values of properties?