static.
On Java 17 and older non-static inner classes contain an implicit reference to their enclosing instance.
Static nested classes do not have such a reference.
Therefore, making an inner class static prevents a common cause of memory leaks
and uses slightly less memory per instance of the class.
The implicit reference was removed for non-Serializable inner classes in Java 18.
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) {}
}
}