Inspectopedia Help

Convert 'object' to 'data object'

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

Inspection Details

Available in:

IntelliJ IDEA 2023.3, Qodana for JVM 2023.3

Plugin:

Kotlin, @snapshot@

Last modified: 13 July 2023