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