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
If you want to intercept assignments and “veto” them, use ___ instead of ‘observable()’.
vetoable()
The handle for ‘Delegates.observable()’ is called ___ the assignment has been performed.
after
The handler passed to ‘vetoable’ is called ___ the assignment of a new property as been performed.
before
A property can delegate its getter and setter to another ___.
property
Delegation to another property is available for both ___ and ___ properties. (member and extension)
top-level; class
What 3 things must a delegate property be?
a top-level property; a member or an extension property of the same class; a member or an extension property of another class
To delegate a property to another property, use the ___ qualifier in the delegate name.
:: (double colon)

What is one use case for delegating a property to another property?
renaming a property in a backwards compatible way

How would you use a map instance as the delegate for a delegated property?

Using a map as a delegate for properties also works for ___ properties if you use a ___ instead of a read-only ___.
‘var’; MutableMap; Map
You can declare ___ variables as delegated properties.
local

For a read-only property (val), a delegate has to provide an operator function ‘getValue()’ with the following parameters:

For a mutable property (var), a delegate has to additionally provide an operator function ‘setValue()’ with the following parameters:

‘getValue()’ and/or ‘setValue()’ functions may be provided either as member functions of the delegate class or ___ ___.
extension functions
You can create delegates as ___ objects without creating new classes using the interfaces ___ and ___ from the Kotlin standard library.
anonymous; ReadOnlyProperty; ReadWriteProperty
