5 concepts · 15 practice questions
Nullability is part of the type: String can never be null, String? can. Safe calls (?.), the Elvis operator (?:) and smart casts handle the null case; !! skips the check and throws if the value is null. Values from Java without annotations are platform types, which the compiler cannot check for you.
fun displayName(user: User?): String {
val name = user?.profile?.name ?: return "Guest"
return name.trim()
}
lateinit var adapter: FeedAdapter // set in onCreate, read after
Sign in to read the rest and take the 15-question test.
Sign in to continue