Java

Java

Made by DeepSource

Method can be declared static JAVA-W1057

Anti-pattern
Major
Autofix

Private final methods that do not access instance fields should be declared static.

Since the method is private and final, it can't possibly be overridden. Therefore, the only possible definition of the method that exists doesn't access any instance fields. So we can safely declare it as static.

Bad Practice

public class Klass {
    private final int aField = 10;

    private final void method() {
        // ...statements that do not access `aField`
    }
}

Recommended

Consider declaring the method static.

public class Klass {
    private final int aField = 10;

    private static final void method() {
        // ...statements that do not access `aField`
    }
}

References