Properties Flashcards

1
Q

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 ___.

A

default implementation; body

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

When a property needs a ___ ___, Kotlin provides it automatically.

A

backing field

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

The ‘field’ identifier can only be used in the ___ of the property.

A

accessors

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

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.

A

default implementation; field

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

If the value of a read-only property is known at compile time, mark it as a compile time constant using the ___ qualifier.

A

const

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Compile time constants must fulfil the following requirements:

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

True or False: Compile time constants can be used in annotations.

A

true

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

The ‘lateinit var’ modifier may not be used on:

A

nullable types; primitive types

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

To check whether a ‘lateinit var’ has already been initialized, use the ___ property.

A

isInitialized

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

The expression after ‘by’ is the ___, because ‘get()’ and ‘set()’ corresponding to the property will be delegated to its ___ and ___ methods.

A

delegate; getValue(); setValue()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

‘lazy()’ is a function that takes a lambda and returns an instance of ‘Lazy’ which can serve as a ___ for implementing a ___ ___.

A

delegate; lazy property

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

By default, the evaluation of lazy properties is ___.

A

synchronized

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

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.

A

LazyThreadSafetyMode.PUBLICATION; lazy()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

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 ___.

A

LazyThreadSafetyMode.NONE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

‘Delegates.observable()’ takes two arguments: the ___ ___ and a ___ for modifications.

A

initial value; handler

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

If you want to intercept assignments and “veto” them, use ___ instead of ‘observable()’.

A

vetoable()

17
Q

The handle for ‘Delegates.observable()’ is called ___ the assignment has been performed.

A

after

18
Q

The handler passed to ‘vetoable’ is called ___ the assignment of a new property as been performed.

A

before

19
Q

A property can delegate its getter and setter to another ___.

A

property

20
Q

Delegation to another property is available for both ___ and ___ properties. (member and extension)

A

top-level; class

21
Q

What 3 things must a delegate property be?

A

a top-level property; a member or an extension property of the same class; a member or an extension property of another class

22
Q

To delegate a property to another property, use the ___ qualifier in the delegate name.

A

:: (double colon)

23
Q

What is one use case for delegating a property to another property?

A

renaming a property in a backwards compatible way

24
Q

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

A
25
Q

Using a map as a delegate for properties also works for ___ properties if you use a ___ instead of a read-only ___.

A

‘var’; MutableMap; Map

26
Q

You can declare ___ variables as delegated properties.

A

local

27
Q

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

A
28
Q

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

A
29
Q

‘getValue()’ and/or ‘setValue()’ functions may be provided either as member functions of the delegate class or ___ ___.

A

extension functions

30
Q

You can create delegates as ___ objects without creating new classes using the interfaces ___ and ___ from the Kotlin standard library.

A

anonymous; ReadOnlyProperty; ReadWriteProperty