Inspectopedia Help

Inner class may be 'static'

Reports inner classes that can be made static.

A static inner class does not keep an implicit reference to its enclosing instance. This prevents a common cause of memory leaks and uses less memory per instance of the class.

Example:

public class Outer { class Inner { // not static public void foo() { bar("x"); } private void bar(String string) {} } }

After the quick-fix is applied:

public class Outer { static class Inner { public void foo() { bar("x"); } private void bar(String string) {} } }

Inspection options

Option

Type

Default

Ignore if annotated by

StringList

[org.junit.jupiter.api.Nested]

Inspection Details

Available in:

IntelliJ IDEA 2023.3, Qodana for JVM 2023.3

Plugin:

Java, 233.SNAPSHOT

Last modified: 13 July 2023