kotlin-types-value-class

Guide Kotlin developers on using @JvmInline value classes for single-field types.

908|42|Updated May 12, 2026
One-click install
npx skills add https://github.com/chrisbanes/skills --skill kotlin-types-value-class-chrisbanes
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: kotlin-types-value-class
Source: https://github.com/chrisbanes/skills/tree/main/skills/kotlin-types-value-class
Command: npx skills add https://github.com/chrisbanes/skills --skill kotlin-types-value-class-chrisbanes

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Developers often need to decide between using a data class or a single-field wrapper for domain types in Kotlin. This skill helps ensure type safety and efficient runtime performance by preferring @JvmInline value classes where appropriate, especially when working with Compose stability considerations.

Core Features & Use Cases

  • Recommends using @JvmInline value class for single-field domain types.
  • Guides when to replace a single-field data class with a value class to avoid unnecessary allocations.
  • Provides guidance on Compose stability implications and interoperability with Java.

Quick Start

Create a minimal value class wrapper for a domain type to ensure type safety and zero-runtime allocation where possible.

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?

Prefer a Kotlin value class for single-field domain types to ensure type safety while avoiding unnecessary allocations at runtime. Use data classes only when multiple fields are required.

How do Kotlin value classes affect Compose stability?

Kotlin value classes support Compose stability by providing zero-runtime allocation for single-field types, ensuring efficient recompositions. This Skill documents their compatibility and stability implications within Compose.

Do I need a value class or a type alias for type safety in Kotlin?

Use a Kotlin value class for true type safety at runtime without allocation overhead, whereas a type alias merely provides a compile-time name without distinct type boundaries. The Skill guides choosing between them.

What are the limitations of using @JvmInline value classes in Kotlin?

Limitations of @JvmInline value classes include supporting only a single field and potential Java interoperability constraints. The Skill outlines when to avoid them in favor of data classes or type aliases.

How do I replace a single-field data class with a value class in Kotlin?

To replace a single-field data class, apply the @JvmInline annotation and implement the value class interface. This transition eliminates unnecessary object allocations while maintaining type safety.

Does a Kotlin value class work well with Java interoperability?

Kotlin value classes have specific Java interoperability considerations due to their underlying inline representation. The Skill documents these compatibility details to ensure seamless cross-language usage.