Does anyone know why:
public void foo()
{
System.out.println(\"Hello\");
return;
System.out.println(\"World!\");
}
Would be rep
I made some try on eclipse and think there are 3 kinds of dead code handling of JDK: 1) no warn, 2) warn and 3) error.
For a typical "IF" conditional compilataion code, JDK detect this and didnt report it as dead code. For a dead code that is caused by a constant boolean flag, JDK detect this and report it at warning level. For dead code that is cause by the program's control flow, JDK detect it as error.
Below is my try:
public class Setting {
public static final boolean FianlDebugFlag = false;
}
class B {
.....
// no warn, it is typical "IF" conditional compilataion code
if(Setting.FianlDebugFlag)
System.out.println("am i dead?");
if(false)
System.out.println("am i dead?");
// warn, as the dead code is caused by a constant boolean flag
if(ret!=null && Setting.FianlDebugFlag)
System.out.println("am i dead?");
if(Setting.FinalDebug)
return null;
System.out.println("am i dea?");
// error, as the dead code is due to the program's control flow
return null;
System.out.println("am i dead");
}