Stop Mixing Up Long IDs with Kotlin Inline Classes
Kotlin inline classes wrap a primitive in a distinct compile-time type without the runtime cost of a regular wrapper class. Here's when they help and where they break down.
ReadMeFeed / Community knowledge
Real questions. Useful conversations. Find the people who know your stack.
Kotlin inline classes wrap a primitive in a distinct compile-time type without the runtime cost of a regular wrapper class. Here's when they help and where they break down.
Scala value classes (AnyVal) give you type-safe domain wrappers like UserId that usually cost nothing at runtime. Here's the mechanism, a worked example, and where boxing still bites.
A library that cross-builds for Scala 2.13 and Scala 3 needs a zero-cost wrapper for identifiers in a hot path, while keeping the public API distinct from the underlying type. Two documented options are Scala 3 opaque type aliases and value classes that extend AnyVal . Opaque types hide their representation outside the defining scope and are erased to the un