A primitive data type stores a basic value directly rather than an object reference. Java separates primitive types such as int from reference types, but Kotlin presents both primitive-like values and wrappers through one type, such as Int. section 8.1.1 section 8.1
The same Kotlin type across contexts
Use Int for ordinary values and collections: val i: Int = 1 val list: List<Int> = listOf(1, 2, 3) Kotlin normally compiles the standalone Int to Java int. As a generic type argument, List<Int> uses boxed java.lang.Integer values because JVM generics require reference types. section 8.1.1
Kotlin also lets number values use methods. For example, coerceIn restricts progress to a valid range while keeping the code concise. section 8.1.1
The representation changes when null is possible. Int? must use a boxed Java type because Java primitives cannot hold null; nullable values therefore follow normal Kotlin null-safety checks. section 8.1.3
Nullable primitive values
data class Person(val name: String, val age: Int? = null) { fun isOlderThan(other: Person): Boolean? { if (age == null || other.age == null) return null return age > other.age } } An unknown age produces null rather than an unsafe comparison. section 8.1.3
Generic collections box primitive values. For large unboxed collections, use specialized arrays such as IntArray; Array<Int> instead stores boxed integers. section 8.1.3 section 8.2.5
val fiveZeros = IntArray(5) val fiveZerosToo = intArrayOf(0, 0, 0, 0, 0)
Compare two concise ways to create an IntArray containing five zeros without boxing its elements. section 8.2.5





