I'm having a hard time finding information about javac
's code elimination capabilities:
I read that if you have something like the following, the if
-statement will be eliminated:
static final boolean DEBUG = false;
if (DEBUG) System.out.println("Hello World!"); // will be removed
But how about this, for example:
static final int VALUE = 3;
if (VALUE > 9) System.out.println("VALUE > 9 ???"); // will this be removed?
Or this:
static final SomeEnum VALUE = SomeEnum.FOO;
if (VALUE==SomeEnum.BAR) System.out.println("Bar???"); // will this be removed?
Since it's very difficult/impossible to analyze a program to find all dead code (probably similar to the halting problem), I would imagine that there are only a few well-defined constructs (like the first example above), which javac
will recognize and remove reliably. Is there a comprehensive list of these constructs?
javap -c
will make it pretty clear... – Gumboil