Main Flashcards
How is called a porcess where a single abstract method can be implemented using anonymous function?
Single Abstract Method Conversion (SAM)
What do you pass instead if an object implements SAM?
lambda
val age = 45. Write a conditional to check if age is even
age % 2 == 0
build a raw String named player
val player : String = “””
Michael
Jordan
“””
If “”” raw String is used do you need to use an escape characters?
NO
For what Raw Strings are useful?
Regex patterns
What kotlin ability we can use to add a function to 3rd party library?
extensions
What type indicates that the function will never coplete normally
Nothing.
val thing : Nothing = TODO()
If we write a function but we do not want to return yet
how can we stop compiler complaining about the error?
By using TODO
fun age() : Int {
TODO()
}
Why Unit in kotlin is useful?
It can be used in generics. For instance, ‹
4 Kotlin language principles
1.Concise 2.Pragmatic 3.Safe 4.Interoperable
What is idiomatic language code
It is a code which is specific for a language
How do we call Kotlin’s ability to work with Java code?
Interoperablility - the ability of computer systems or software to exchange and make use of information
How to define that member variable is read-only ?
var hasBeenHnadled = false private set // Allow read-only
@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?
by specifying variable’s set() to private in the reposisitory
var appConfiguration: AppConfiguration private set
If we have a large number of elements would we use SparseArray over HashMap
NO. Because SparseArray is only efficient if a collection is small. Less than 1000 elements
What should be used if we have maps of maps? HashMap or SparseArray?
SparseArray
How are called those values for function parameters fun foo(a: Int = 0, b: String = "") { ... }
default values
How is called the usage of $variable in the String?
String interpolation
how is called this code
is Foo -> …
Instance check
how is called this operation
for ((k, v) in map) {
println(“$k -> $v”)
}
traversing a map or list of pairs
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) { … }
Using ranges
Is that map
val map = mapOf(“a” to 1, “b” to 2, “c” to 3)
read-only map ?
yes