Inspectopedia Help

Sealed subclass without state and overridden equals

Reports direct inheritors of sealed classes that have no state and overridden equals() method.

It's highly recommended to override equals() to provide comparison stability, or convert the class to an object to reach the same effect.

Example:

sealed class Receiver { class Everyone : Receiver() class User(val id: Int) : Receiver() }

The quick-fix converts a class into an object:

sealed class Receiver { object Everyone : Receiver() class User(val id: Int) : Receiver() }

Inspection Details

Available in:

IntelliJ IDEA 2023.3, Qodana for JVM 2023.3

Plugin:

Kotlin, @snapshot@

Last modified: 13 July 2023