public void someMethod(Object obj) { doFirst(obj); doSecond(obj); return;
doThird(obj); doFourth(obj); doFifth(obj); .... }
很不幸,这不能被编译成:
///// javac: code/ComplexTest.java:15: unreachable statement Complex c = new Complex(3,4); ^ 1 error ///// jikes: Found 1 semantic error compiling "code/ComplexTest.java":
〈----------------------------- 15. Complex c = new Complex(3,4); . . . 18. System.out.PRintln(Complex.conjugate(c)); ------------------------------------------------〉 *** Error: These statements are unreachable.
然而,if(true)欺骗了编译器,并让编译器认为下列的这些是合法的:
public void someMethod(Object obj) { doFirst(obj); doSecond(obj); if(true) return;