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()
What keyword is used to declare a function?
fun
Class member functions are ________
virtual
Class members are ________ by default
public
Classes are ________ by default
final
If a class member is not initialized during construction what keyword do you use to initialize it?
lateinit
What keyword is used to create a Singleton?
object
What keyword is used for static methods?
companion
What is view binding a subset of?
Data Binding
In most cases view binding replaces what function?
findViewById()
What file do you change to enable view binding?
Gradle Module
What function is used with view binding to give direct reference to the root view of the corresponding layout file?
getRoot()
What does ViewBinding change the IDs of the XML layout file to?
camelCase
What library did we use for JSON with Kotlin?
GSON
What kind of class should you use when working with JSON?
data
What keyword should you use to make data class field names different from the JSON names?
@SerializedName(“key_name”)
How do you parse a class object into JSON using GSON?
Gson().toJson(Object)