Skip to main content
InterviewHubPRO
Section Overview
Q47

Question 47 of 50

Part 3: K2 Compiler, KMP, Advanced Metaprogramming & Optimization (25 - 35)

94%
Kotlin & Coroutines (50 Qs)•Part 3: K2 Compiler, KMP, Advanced Metaprogramming & Optimization (25 - 35)

Value Classes (`@JvmInline value class`): Zero-allocation domain modeling.

senior LevelCode ExamplePerformance

In Simple Words: Wrapping primitives (e.g. UserId(val value: Long)) in standard classes creates heap allocation overhead for millions of IDs:

kotlin
@JvmInline
value class UserId(val id: Long)
  • Compile-Time: Provides strict type safety (cannot accidentally pass an OrderId into a function expecting a UserId).
  • Runtime: The JVM compiler strips the wrapper and passes raw primitive long values in registers with zero heap memory allocation!