I can't see anyway that you could stop recursive call to bar() and get back to foo without using return values and reaching a case. If you exit the JVM before the call to bar then you will never get back to foo so that's not an option. Obviously you can't place return as the first statement in the method bar() since any statements that come after return will be unreachable. You would need to use return values.
Code:public class C{ public static void main(String[] args){ foo(); } public static void foo() { bar(true); } public static void bar(boolean b){ if(b){ System.out.println("1"); }else{ bar(true); // never invoked } } }




Reply With Quote