Main Flashcards

1
Q

How is called a porcess where a single abstract method can be implemented using anonymous function?

A

Single Abstract Method Conversion (SAM)

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

What do you pass instead if an object implements SAM?

A

lambda

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

val age = 45. Write a conditional to check if age is even

A

age % 2 == 0

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

build a raw String named player

A

val player : String = “””
Michael
Jordan
“””

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

If “”” raw String is used do you need to use an escape characters?

A

NO

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

For what Raw Strings are useful?

A

Regex patterns

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

What kotlin ability we can use to add a function to 3rd party library?

A

extensions

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

What type indicates that the function will never coplete normally

A

Nothing.

val thing : Nothing = TODO()

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

If we write a function but we do not want to return yet

how can we stop compiler complaining about the error?

A

By using TODO
fun age() : Int {
TODO()
}

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

Why Unit in kotlin is useful?

A

It can be used in generics. For instance, ‹

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

4 Kotlin language principles

A

1.Concise 2.Pragmatic 3.Safe 4.Interoperable

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

What is idiomatic language code

A

It is a code which is specific for a language

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

How do we call Kotlin’s ability to work with Java code?

A

Interoperablility - the ability of computer systems or software to exchange and make use of information

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

How to define that member variable is read-only ?

A
var hasBeenHnadled = false
private set // Allow read-only
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q
@JsonClass(generateAdapter = true)
data class AppConfiguration(
    val version: Int,
    val diagnosisKeysPerSubmit: Int,
    val pollingIntervalMinutes: Long,
    val tokenLength: Int
)
Let's say we have data which should be read-only, like the example above. How can we achieve this?
A

by specifying variable’s set() to private in the reposisitory

var appConfiguration: AppConfiguration
    private set
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

If we have a large number of elements would we use SparseArray over HashMap

A

NO. Because SparseArray is only efficient if a collection is small. Less than 1000 elements

17
Q

What should be used if we have maps of maps? HashMap or SparseArray?

A

SparseArray

18
Q
How are called those values for function parameters
fun foo(a: Int = 0, b: String = "") { ... }
A

default values

19
Q

How is called the usage of $variable in the String?

A

String interpolation

20
Q

how is called this code

is Foo -> …

A

Instance check

21
Q

how is called this operation
for ((k, v) in map) {
println(“$k -> $v”)
}

A

traversing a map or list of pairs

22
Q

How would you call the usage of this
for (i in 1..100) { … } // closed range: includes 100
for (i in 1 until 100) { … } // half-open range: does not include 100
for (x in 2..10 step 2) { … }
for (x in 10 downTo 1) { … }
if (x in 1..10) { … }

A

Using ranges

23
Q

Is that map
val map = mapOf(“a” to 1, “b” to 2, “c” to 3)
read-only map ?

A

yes