Junior — Middle
What is the difference between primitive and reference object types in Kotlin?
sobes.tech AI
Answer from AI
In Kotlin, primitive types (like Int, Boolean) are usually represented as primitives at the JVM level for efficiency, but in the language, they are objects with methods. Reference types are objects stored on the heap and referenced by variables.
Main difference:
- Primitive types store values directly and are more memory- and performance-efficient.
- Reference types store a reference to an object in memory.
For example, Int is a primitive type, while String is a reference type. When passing primitives, the value is copied; when passing reference types, the reference to the object is copied.