Back to Intellij Community

ConvertObjectToDataObject

plugins/kotlin/code-insight/descriptions/resources-en/inspectionDescriptions/ConvertObjectToDataObject.html

2025.3-rc-2548 B
Original Source

Reports object that can be converted to data object

data object auto-generates toString, equals and hashCode

The inspection suggests to convert object to data object in 2 cases:

  • When custom toString returns name of the class
  • When object inherits sealed class/interface

Example:

object Foo {
        override fun toString(): String = "Foo"
    }

After the quick-fix is applied:

data object Foo

This inspection only reports if the Kotlin language level of the project or module is 1.9 or higher