A method that is never called is dead code, and should be removed. Cleaning out dead code decreases the size of the maintained codebase, making it
easier to understand the program and preventing bugs from being introduced.
This rule detects methods that are never referenced from inside a translation unit, and cannot be referenced from the outside.
Code examples
Noncompliant code example
public class Server {
public void start() { // Compliant, publicly available
log('start');
}
private void clear() { // Noncompliant, not used anywhere
}
private void log(String msg) { // Compliant, called from 'start()'
System.debug(msg);
}
}