0
0
Kotlinprogramming~20 mins

Why Kotlin has no primitive types at source level - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Kotlin Primitive Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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)
}
ACompilation error
Btrue
Cfalse
DRuntime exception
Attempts:
2 left
💡 Hint
Consider how Kotlin handles boxed integers and identity checks.
🧠 Conceptual
intermediate
1: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?
ATo simplify the language and unify types under a single system
BBecause Kotlin does not support primitive types at all
CTo force developers to use only boxed types for safety
DBecause JVM does not allow primitive types
Attempts:
2 left
💡 Hint
Think about how Kotlin aims to reduce complexity for developers.
🔧 Debug
advanced
2: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)
}
ACompilation error: variable y must be non-null
BNullPointerException at runtime
CCompilation succeeds and prints 10
D
Type mismatch: operator '+' cannot be applied to 'Int' and 'Int?'
Attempts:
2 left
💡 Hint
Check how Kotlin handles operations between nullable and non-nullable types.
📝 Syntax
advanced
1: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.
Aval a = 5 as Int
Bval a: Int? = 5
Cval a = 5.toInt()
Dval a: Int = 5
Attempts:
2 left
💡 Hint
Nullable types are boxed in Kotlin.
🚀 Application
expert
2:30remaining
How Kotlin optimizes primitive types at runtime
Which statement best describes how Kotlin handles primitive types during compilation and runtime?
AKotlin source code uses only reference types, but the compiler generates JVM bytecode using primitives when possible
BKotlin requires developers to manually specify primitive types for optimization
CKotlin always uses boxed types at runtime for consistency
DKotlin does not run on JVM and thus does not use primitives
Attempts:
2 left
💡 Hint
Think about Kotlin's goal to combine simplicity with performance on JVM.