No Empty Class Bodies

ID

kotlin.no_empty_class_bodies

Severity

info

Remediation Complexity

medium

Remediation Risk

low

Remediation Effort

medium

Resource

Code Smell

Language

Kotlin

Tags

best-practice, code-style

Description

Reports class, interface, object, or companion-object declarations whose body is present but empty (class Foo {}). When a class body contains no members, the braces are redundant and should be removed.

Rationale

Kotlin allows class Foo without braces when there are no members. The brace-free form is shorter, unambiguous, and idiomatic. An empty {} suggests either a placeholder that was never completed or a copy-paste leftover.

// Bad
class Empty {}
object Config {}
interface Marker {}

// Good
class Empty
object Config
interface Marker

Remediation

Remove the empty braces. Most IDEs offer a one-click inspection fix. If the empty body is intentional (e.g. a future extension point), add a comment inside the braces to document the intent and suppress the warning:

class ExtensionPoint {
    // reserved for future use
}