Skip to content

no-empty-class-body

Kotlinstyleno fixdefault: offkotlin/ktlint

Reports a class or interface with { } and nothing in it (class A {}).

An empty body adds two characters and says nothing. Kotlin does not need the braces for a class without members.

To fix, delete the braces: class A.

Reported
class A {}
class B { }
class C {
val x = 1
}
interface D {}
val o = object : Any() {}
kotlin:
lint:
rules:
no-empty-class-body: warn # off (default), warn, error

Enabled by the presets: kotlin/ktlint.

Suppress one line with sudsy-disable-next-line no-empty-class-body in a comment of the file’s language.

The same check in other tools. full: Sudsy reports what the upstream rule reports; partial: only part of it, as the last column says.

Tool Rule Match What differs
ktlint no-empty-class-body partial Comments inside the braces do not count as content.