Unused private methods, excepting methods with annotations and special methods overriding Java's default behaviour, constitute dead code and should therefore be removed.
Apply with the Grit CLI
grit apply unused_private_methods
Removes unused non-constructor method
BEFORE
public class Foo implements Serializable { private Foo(){} public static void doSomething(){ Foo foo = new Foo(); } public void sayHi() { this.usedPrivateMethod(); } private void usedPrivateMethod() { } private void unusedPrivateMethod() { } private void anotherUnusedPrivateMethod() { } }
AFTER
public class Foo implements Serializable { private Foo(){} public static void doSomething(){ Foo foo = new Foo(); } public void sayHi() { this.usedPrivateMethod(); } private void usedPrivateMethod() { } }
Does not remove annotated and override methods
JAVA
public class Foo implements Serializable { @Annotation private void annotatedMethod(){ this.usedPrivateMethod(); } private void writeObject(ObjectOutputStream s){ } private void readObject(ObjectInputStream in){ } }