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
- Type Aliases
- Inline Value Classes
- Use Cases
- Limitations