Back to Intellij Community

EmptyClass

java/java-impl/resources/inspectionDescriptions/EmptyClass.html

2025.3-rc-2983 B
Original Source

Reports empty classes and empty Java files.

A class is empty if it doesn't contain any fields, methods, constructors, or initializers. Empty classes are sometimes left over after significant changes or refactorings.

Example:

class Example {
    List<String> getList() {
       return new ArrayList<>() {

       };
    }
  }

After the quick-fix is applied:

class Example {
    List<String> getList() {
       return new ArrayList<>();
    }
  }

Configure the inspection:

  • Use the Ignore if annotated by option to specify special annotations. The inspection will ignore the classes marked with these annotations.

  • Use the Ignore class if it is a parametrization of a super type option to ignore classes that parameterize a superclass. For example:

  • Use the Ignore subclasses of java.lang.Throwable to ignore classes that extend java.lang.Throwable.

  • Use the Comments count as content option to ignore classes that contain comments.