Search:     Advanced search
server monitoring

Dead Code: Unused Method

Article ID: 111
Last updated: 06 May, 2008
Views: 278
Posted: 06 May, 2008
by: Tech Pubs S.
Updated: 06 May, 2008
by: Tech Pubs S.

Dead Code: Unused Method

Abstract

This method is not reachable from any method outside the class.

Description

This method is never called or is only called from other dead code.

Examples

Example 1: In the following class, the method doWork() can never be called.

	public class Dead {
private void doWork() {
System.out.println("doing work");
}
public static void main(String[] args) {
System.out.println("running Dead");
}
}

Example 2: In the following class, two private methods call each other, but since neither one is ever invoked from anywhere else, they are both dead code.

	public class DoubleDead {
private void doTweedledee() {
doTweedledumb();
}
private void doTweedledumb() {
doTweedledee();
}
public static void main(String[] args) {
System.out.println("running DoubleDead");
}
}

(In this case it is a good thing that the methods are dead: invoking either one would cause an infinite loop.)

This article was:   Helpful | Not Helpful
Prev   Next
Double Free     Dead Code: Unused Field