Skip to content

Files

Latest commit

 

History

History
40 lines (31 loc) · 607 Bytes

no-empty-static-block.md

File metadata and controls

40 lines (31 loc) · 607 Bytes

Pattern: Empty static initialization block

Issue: -

Description

Empty static blocks in classes are likely the result of incomplete refactoring and serve no purpose. They should either be removed or documented with a comment explaining their intended use.

Examples

Example of incorrect code:

class Foo {
  static {}
}

class Bar {
  static {
  }
}

Example of correct code:

class Foo {
  static {
    // Reserved for future initialization logic
  }
}

class Bar {
  static {
    initializeStaticFields();
  }
}

class Baz {
  // No static block needed
}