Properties Flashcards
If you need to change the visibility of an accessor or to annotate it, but don’t need to change the ___ ___, you can define the accessor without defining it’s ___.
default implementation; body
When a property needs a ___ ___, Kotlin provides it automatically.
backing field
The ‘field’ identifier can only be used in the ___ of the property.
accessors
A backing field will be generated for a property if it uses the ___ ___ of at least one of the accessors, or if a custom accessor references it through the ___ identifier.
default implementation; field
If the value of a read-only property is known at compile time, mark it as a compile time constant using the ___ qualifier.
const
Compile time constants must fulfil the following requirements:
Top-level, or member of an object declaration or a companion object; Initialized with a value of type ‘String’ or a primitive type; No custom getter
True or False: Compile time constants can be used in annotations.
true
The ‘lateinit var’ modifier may not be used on:
nullable types; primitive types
To check whether a ‘lateinit var’ has already been initialized, use the ___ property.
isInitialized
The expression after ‘by’ is the ___, because ‘get()’ and ‘set()’ corresponding to the property will be delegated to its ___ and ___ methods.
delegate; getValue(); setValue()
‘lazy()’ is a function that takes a lambda and returns an instance of ‘Lazy’ which can serve as a ___ for implementing a ___ ___.
delegate; lazy property
By default, the evaluation of lazy properties is ___.
synchronized
If the synchronization of initialization of a delegate is not required, so that multiple threads can execute it simultaneously, pass ___ as a parameter to the ___ function.
LazyThreadSafetyMode.PUBLICATION; lazy()
If you’re sure that the initialization will always happen on the same thread as the one where you use the property, you can use ___.
LazyThreadSafetyMode.NONE
‘Delegates.observable()’ takes two arguments: the ___ ___ and a ___ for modifications.
initial value; handler