What is inline class used for vs type alias in Kotlin?
Answer
Both give alternative names to types, but they serve different purposes. A type alias (typealias UserId = Long) is purely a compile-time synonym — UserId and Long are completely interchangeable, providing no type safety between them. An inline/value class (@JvmInline value class UserId(val id: Long)) creates a distinct type in the type system — you cannot accidentally pass a ProductId where a UserId is expected even if both wrap a Long. At runtime, the value class is represented as the wrapped type (no boxing), so there is zero performance overhead. Use value classes for strong domain types; use type aliases only for readability.
Previous
What is the difference between hot and cold flows in Kotlin?
Next
What is Jetpack Compose and how does it relate to Kotlin?