Challenge - 5 Problems
Data Types Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
📝 Syntax
intermediate2:00remaining
Kotlin Type Inference Behavior
What is the inferred type of the variable
result in the following Kotlin code?Android Kotlin
val result = listOf(1, 2, 3).map { it * 2 }
Attempts:
2 left
💡 Hint
Think about what the
map function returns when applied to a list of integers.✗ Incorrect
The
map function returns a List of the transformed elements. Since it * 2 is an integer operation, the resulting list is of type List.❓ ui_behavior
intermediate2:00remaining
Kotlin Variable Type and UI Display
Given this Kotlin code snippet in an Android app, what will be displayed in the TextView?
Android Kotlin
val message = "Hello" + 123 textView.text = message
Attempts:
2 left
💡 Hint
Consider how Kotlin handles string concatenation with numbers.
✗ Incorrect
Kotlin converts the number 123 to a string and concatenates it directly without spaces, so the TextView shows "Hello123".
❓ lifecycle
advanced2:00remaining
Type Inference Impact on Android Lifecycle
Consider this Kotlin property in an Android Activity:
val count = 0What is the type of
count and what happens if you try to assign count = 5 later in the Activity lifecycle?Attempts:
2 left
💡 Hint
Look at the keyword used to declare
count and what it means in Kotlin.✗ Incorrect
The
val keyword declares an immutable variable. Its type is inferred as Int from the initial value 0. Reassigning it causes a compilation error.advanced
2:00remaining
Type Inference in Navigation Arguments
In Kotlin Android Navigation, you pass an argument to a destination like this:
val action = HomeFragmentDirections.actionToDetail(itemId = 42) findNavController().navigate(action)What is the inferred type of
itemId in the generated code?Attempts:
2 left
💡 Hint
Look at the value passed to
itemId and how Kotlin infers types from literals.✗ Incorrect
The literal 42 is an Int by default in Kotlin, so the generated argument type is Int.
🔧 Debug
expert2:00remaining
Debugging Type Inference with Nullable Types
What error will this Kotlin code produce when compiled?
Android Kotlin
val name = null val length = name.length
Attempts:
2 left
💡 Hint
Consider what Kotlin infers when you assign null without a type.
✗ Incorrect
Kotlin requires an explicit type when assigning null without a type. The code causes a compilation error: Variable 'name' must have a type explicitly specified.