0Pricing
Kotlin Academy · Lesson

Limitations

What value classes cannot do.

Knowing the Boundaries

Value classes are powerful but constrained. Understanding their limits helps you choose the right tool and avoid surprises.

Exactly One Property

A value class wraps a single value. To group multiple fields you need a regular class or a data class.

// @JvmInline value class Range(val lo: Int, val hi: Int) // not allowed

data class Range(val lo: Int, val hi: Int)

fun main() {
    println(Range(1, 10))
}

All lessons in this course

  1. Type Aliases
  2. Inline Value Classes
  3. Use Cases
  4. Limitations
← Back to Kotlin Academy