INFO5126 Quiz #1 Flashcards
Who developed Kotlin?
JetBrains
How does Kotlin compile to native code?
LLVM
What are the 5 reasons to use Kotlin? (Can’t Sell In The Nude)
- Concise
- Safe
- Interoperable
- Tool Friendly
- No checked exceptions
Why is Kotlin considered safe?
Avoids entire classes of errors like Null Pointer Exception
Which keyword is used for read only variables?
val
Which keyword is used for mutable variables?
var
How do you perform string interpolation?
$ and { }
How do you test that two variables refer to the same object?
===
What keyword is used for switch statements?
when
What is the Elvis operator?
?:
What operator is used to return the non-null type value and throw an exception if the value is null?
!!
val l = b!!.length
What operator returns the expression on the left if not null and the expression on the right if null?
?:
val l = b?.length ?: 1
How do you filter out non-null elements from a collection of Nullable type?
filterNotNull()
What function instantiates an immutable list?
listOf()
What function instantiates a mutable list?
mutableListOf()