Challenge - 5 Problems
Kotlin Primitive Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of Kotlin code using Int and boxing
What is the output of this Kotlin code snippet?
Kotlin
fun main() { val a: Int = 1000 val b: Int? = a val c: Int? = a println(b === c) }
Attempts:
2 left
💡 Hint
Consider how Kotlin handles boxed integers and identity checks.
✗ Incorrect
Kotlin uses boxed types for nullable Ints. Each nullable Int is a separate object, so identity (===) returns false.
🧠 Conceptual
intermediate1:30remaining
Reason Kotlin hides primitive types at source level
Why does Kotlin not expose primitive types like
int or float directly in its source code?Attempts:
2 left
💡 Hint
Think about how Kotlin aims to reduce complexity for developers.
✗ Incorrect
Kotlin hides primitive types to provide a simpler, unified type system that automatically optimizes to primitives on the JVM, improving developer experience.
🔧 Debug
advanced2:00remaining
Identify the error in Kotlin code mixing primitives and nullables
What error occurs when running this Kotlin code?
Kotlin
fun main() { val x: Int = 10 val y: Int? = null val z = x + y println(z) }
Attempts:
2 left
💡 Hint
Check how Kotlin handles operations between nullable and non-nullable types.
✗ Incorrect
Kotlin does not allow direct arithmetic between non-nullable and nullable types without explicit null checks or safe calls.
📝 Syntax
advanced1:30remaining
Which Kotlin code snippet correctly forces boxing of an Int?
Select the code snippet that forces the Kotlin compiler to box an Int value.
Attempts:
2 left
💡 Hint
Nullable types are boxed in Kotlin.
✗ Incorrect
Declaring an Int as nullable (Int?) forces boxing because it can hold null, which primitives cannot.
🚀 Application
expert2:30remaining
How Kotlin optimizes primitive types at runtime
Which statement best describes how Kotlin handles primitive types during compilation and runtime?
Attempts:
2 left
💡 Hint
Think about Kotlin's goal to combine simplicity with performance on JVM.
✗ Incorrect
Kotlin source code hides primitives for simplicity, but the compiler emits JVM primitives to optimize performance transparently.