kotlin-types-value-class

Guide Kotlin @JvmInline value class versus data class selection for single-field domain types.

Updated Aug 23, 2026
One-click install
npx skills add https://github.com/soygabimoreno/Los-ANDROIDES --skill kotlin-types-value-class
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: kotlin-types-value-class
Source: https://github.com/soygabimoreno/Los-ANDROIDES/tree/main/.agents/skills/kotlin-types-value-class
Command: npx skills add https://github.com/soygabimoreno/Los-ANDROIDES --skill kotlin-types-value-class

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill helps you avoid misuse of raw primitives (like String or Long) by choosing the right Kotlin type for domain meaning and for Compose performance stability.

Core Features & Use Cases

  • Single-field domain types: Convert “wrapper” data classes that hold exactly one value into @JvmInline value class for better type safety and less runtime overhead.
  • Compose stability improvement: Use value classes to reduce “unstable parameter” warnings at Compose boundaries when the underlying type is stable.
  • Correct review decisions: Diagnose common mistakes such as missing @JvmInline, using value classes without domain meaning, and breaking equality/serialization expectations.

Quick Start

Use this skill when reviewing a Kotlin model or UI state to decide whether a single-field wrapper should become an @JvmInline value class for stability and domain safety.

Frequently Asked Questions about kotlin-types-value-class

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
When should I use a Kotlin value class instead of a data class for domain types?

Use Kotlin value classes instead of data classes for single-field domain types to prevent primitive misuse and reduce runtime overhead. Value classes provide better type safety without the allocation cost of standard wrapper classes.

How do I fix unstable parameter warnings in Jetpack Compose with value classes?

To fix unstable parameter warnings in Jetpack Compose, use @JvmInline value classes wrapping stable primitives or Strings. This ensures Compose treats the parameters as stable, reducing unnecessary recompositions at UI boundaries.

What is the difference between @JvmInline value classes and data classes in Kotlin?

@JvmInline value classes avoid boxing overhead by unboxing to underlying primitives at runtime, unlike data classes which allocate objects. Choose value classes for single-field domain wrappers, but note they have different equality and serialization semantics.

How do I convert a single-field data class to an @JvmInline value class for type safety?

Convert a single-field wrapper data class to an @JvmInline value class by annotating it with @JvmInline and the value modifier. This ensures the compiler inlines the underlying type, preventing primitive misuse while maintaining domain meaning.

What are the limitations of using Kotlin value classes for domain modeling?

Limitations of Kotlin value classes include breaking expected equality and serialization semantics if not handled carefully. You should not use them for multi-field types or when domain logic requires reference equality and standard object allocation behaviors.

Do I need @JvmInline for Kotlin value classes to prevent boxing in hot paths?

Yes, you need @JvmInline for Kotlin value classes to ensure unboxing rules apply and prevent boxing overhead in hot paths. Missing @JvmInline loses the performance benefits and may not resolve Compose stability expectations as intended.