Data objects are a new Kotlin language feature introduced in version 1.7.20 and are currently planned to be released in version 1.9. We’ll take a closer look at what they are and what issue they are trying to solve.
What issue are data objects solving?
Below we have a typical example of a sealed class hierarchy where we are using a sealed interface (we could also use a sealed class) to define possible states for a Profile screen. We are using a data class for the success state and an object for error and loading states since we don’t need any additional information.