kotlin-types-value-class

Evaluate value class versus data class usage in Kotlin code.

13|Updated Jun 24, 2021
One-click install
npx skills add https://github.com/costular/Minitask --skill kotlin-types-value-class-costular
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: kotlin-types-value-class
Source: https://github.com/costular/Minitask/tree/main/.agents/skills/kotlin-types-value-class
Command: npx skills add https://github.com/costular/Minitask --skill kotlin-types-value-class-costular

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) and references (resource) components.

What problem does it solve?

This Skill helps developers avoid unnecessary object creation by suggesting when to use a @JvmInline value class instead of a data class in Kotlin.

Core Features & Use Cases

  • Type Selection: Determines the most suitable class for representing domain values.
  • Domain Knowledge: Utilizes the context of the type's use to guide the selection.
  • Compose Stability: Assists in maintaining the stability of Compose UI parameters.
  • Use Case: When designing a Kotlin class that wraps a primitive or a domain-specific value, use this Skill to choose between a value class and a data class for performance and memory efficiency.

Quick Start

Analyze the use of types in the Kotlin class 'UserSettings' with the skill 'kotlin-types-value-class'.

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?▼

Choose a Kotlin value class over a data class when wrapping a single field to optimize performance and memory efficiency by avoiding unnecessary object creation during runtime.

How do value classes affect Compose UI parameter stability in Kotlin?▼

Value classes help maintain Compose UI parameter stability by providing lightweight, predictable type wrappers. Evaluating single-field type usage ensures these domain values do not trigger unnecessary recompositions.

What is the performance difference between Kotlin value classes and data classes?▼

Kotlin value classes eliminate the overhead of object allocation for single-field wrappers, offering better memory efficiency than data classes. Data classes allocate heap objects, while inline value classes are flattened at compile time.

How do I analyze existing Kotlin code to refactor data classes into value classes?▼

Analyze single-field type usage and domain relevance within your Kotlin codebase. The evaluation checks if the type wraps a primitive or domain-specific value to determine if a value class is applicable for performance optimization.

Can I use a Kotlin value class for a type with multiple fields?▼

No, Kotlin value classes only support a single field. You must use a data class for types with multiple fields, as value classes are specifically designed to inline single-domain values for memory efficiency.